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:

  1. Download Turbolift, I know it is an old tool.

    git clone https://github.com/cloudnull/turbolift
    cd turbolift
    
  2. In order to get and isolated installation, we are going to create a Python Virtual Environment (virtualenv)

    mkvirtualenv turbolift
    workon turbolift
    
  3. Install the tool

    pip install turbolift
    
  4. Now, prior to start to play with the API calls, we need to grab some data to authenticate with the API:

    VariableDefinition
    USERNAMEThis is the Rackspace Public Cloud username
    APIKEYThis is your API-KEY
    REGIONThis is the Region where the Cloud Files are located (dfw, ord, iad, lon, hkg)
    TOKENThe TOKEN is generated after you get authenticated
    ENDPOINTThis ENDPOINT is given also after you get authenticated
  5. 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.

  6. 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.

😄

Edit this page

Luis Cacho
Luis Cacho
Senior Container Infrastructure Consultant

Senior Container Infrastructure Consultant at Red Hat | DevOps Practitioner | Kubernetes Enthusiast | Ansible Ninja | Data Science Noob

Next
Previous

Related