Skip to content

Instantly share code, notes, and snippets.

@mikhno-s
Created February 18, 2021 13:59
Show Gist options
  • Save mikhno-s/72bce6054464c2b317e1663c6451abce to your computer and use it in GitHub Desktop.
Save mikhno-s/72bce6054464c2b317e1663c6451abce to your computer and use it in GitHub Desktop.
Delete rackspace server
#!/bin/bash
set -x
USERNAME=$1
APIKEY=$2
SERVER=$3
if [[ -z $USERNAME || -z $APIKEY ]]; then
echo "Run $0 \$USERNAME \$APIKEY \$SERVER"
exit 1
fi
identity_data=`curl -s https://identity.api.rackspacecloud.com/v2.0/tokens -X POST -d "{\"auth\":{\"RAX-KSKEY:apiKeyCredentials\":{\"username\":\"$USERNAME\",\"apiKey\":\"$APIKEY\"}}}" -H "Content-type: application/json"`
token_id=`echo "$identity_data" | jq -r .access.token.id`
tenant_id=`echo "$identity_data" | jq -r .access.token.tenant.name`
servers=`curl https://lon.servers.api.rackspacecloud.com/v2/$tenant_id/servers \
-X GET \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "X-Auth-Token: $token_id"`
server_id=`echo $servers | jq -r ".servers[] | select(.name==\"${SERVER}\") | .id"`
curl https://lon.servers.api.rackspacecloud.com/v2/$tenant_id/servers/$server_id \
-X DELETE \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "X-Auth-Token: $token_id"
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment