28 lines
829 B
Bash
Raw Normal View History

resize_vps() {
LABEL="$1"
NEW_TYPE="$2"
LINODE_ID=$(curl -s -H "Authorization: Bearer $LINODE_API_TOKEN" \
https://api.linode.com/v4/linode/instances | \
jq -r --arg LABEL "$LABEL" '.data[] | select(.label == $LABEL) | .id')
if [ -z "$LINODE_ID" ]; then
echo "❌ No Linode found with label '$LABEL'"
exit 1
fi
echo "Resizing Linode '$LABEL' to type '$NEW_TYPE'..."
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $LINODE_API_TOKEN" \
-d '{"type": "'"$NEW_TYPE"'"}' \
https://api.linode.com/v4/linode/instances/$LINODE_ID/resize)
if [[ "$HTTP_STATUS" == "200" ]]; then
echo "✅ Linode $LABEL resized to $NEW_TYPE."
else
echo "❌ Failed to resize VPS. HTTP status: $HTTP_STATUS"
fi
}