Bulk Delete Rackspace Cloud Files data via API
How to delete the Data and Cloud Files Containers using Rackspace Cloud Files API, cURL and Turbolift
Sometimes it is necessary to delete all the content of the Cloud Files containers, however, the API does not have a proper method to delete the data and the containers on the same API call. Also, accoring to the documentation, you can only delete empty containers.
So, in cases where you need to delete the data and the containers at the same time, you should follow the next steps:
Download Turbolift, I know it is an old tool.
git clone https://github.com/cloudnull/turbolift cd turbolift
In order to get and isolated installation, we are going to create a Python Virtual Environment (virtualenv)
mkvirtualenv turbolift workon turbolift
Install the tool
pip install turbolift
Now, prior to start to play with the API calls, we need to grab some data to authenticate with the API:
Variable Definition USERNAME This is the Rackspace Public Cloud username APIKEY This is your API-KEY REGION This is the Region where the Cloud Files are located (dfw, ord, iad, lon, hkg) TOKEN The TOKEN is generated after you get authenticated ENDPOINT This ENDPOINT is given also after you get authenticated Next step, we are going to use cURL, to perform all the API calls:
- First of all, get the TOKEN:
USERNAME=YOUR-USERNAME APIKEY=YOUR-APIKEY TOKEN=$(curl -s -XPOST https://identity.api.rackspacecloud.com/v2.0/tokens \ -d'{"auth":{"RAX-KSKEY:apiKeyCredentials":{"username":"'$USERNAME'","apiKey":"'$APIKEY'"}}}' \ -H"Content-type:application/json" | jq '.access.token.id' | tr -d "\"")
- Next step, get the ENDPOINT:
ENDPOINT=$(curl -s -XPOST https://identity.api.rackspacecloud.com/v2.0/tokens \ -d'{"auth":{"RAX-KSKEY:apiKeyCredentials":{"username":"'$CL_USERNAME'","apiKey":"'$APIKEY'"}}}' \ -H"Content-type:application/json" | jq '.access.serviceCatalog[] | select((.name=="cloudFiles") or (.name=="cloudFilesCDN")) | {name} + . endpoints[] | .publicURL' | tr -d "\"" | grep -v cdn | grep -i $REGION)
In this case we are skipping all te CDN endpoints, but you can add them if is necessary.
With all the collected data, next step is use turbolift to delete the Cloud Files container and their data. To do it, I use a for-loop:
for i in $(curl -s -H "X-Auth-Token: $TOKEN" $ENDPOINT); do turbolift -u $USERNAME -a $APIKEY --os-rax-auth $REGION delete -c $i ; done
Now, you have all the Data and Cloud Files containers deleted on one region.
😄