Difference between revisions of "Rackspace API/Cloud Block Storage"

From Christoph's Personal Wiki
Jump to: navigation, search
Line 1: Line 1:
 +
This article will show various examples and techniques for working with Rackspace's [http://www.rackspace.com/cloud/block-storage/ Cloud Cloud Block Storage] (CBS) RESTful API.
 +
 
==HOWTO: boot from volume (BfV)==
 
==HOWTO: boot from volume (BfV)==
 
In this section, I will show you how to boot from a [http://www.rackspace.com/cloud/block-storage/ Cloud Block Storage] (CBS) volume entirely using simple [http://docs.rackspace.com/ API calls] (via [[curl|cURL]]).
 
In this section, I will show you how to boot from a [http://www.rackspace.com/cloud/block-storage/ Cloud Block Storage] (CBS) volume entirely using simple [http://docs.rackspace.com/ API calls] (via [[curl|cURL]]).

Revision as of 18:03, 14 November 2014

This article will show various examples and techniques for working with Rackspace's Cloud Cloud Block Storage (CBS) RESTful API.

HOWTO: boot from volume (BfV)

In this section, I will show you how to boot from a Cloud Block Storage (CBS) volume entirely using simple API calls (via cURL).

The examples in this article will do the following:

  • Create a SATA CBS volume in DFW; and
  • Boot a 1GB Performance-1 Cloud Server from that CBS volume in DFW;
  • Step #0: Setup your environment variables:
$ ACCOUNT=012345
$ USERNAME=myraxusername
$ API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
$ REGION=dfw
$ CBS_ENDPOINT=https://${REGION}.blockstorage.api.rackspacecloud.com/v1/${ACCOUNT}
$ SERVERS_ENDPOINT= https://${REGION}.servers.api.rackspacecloud.com/v2/${ACCOUNT}
$ IMAGE_ID="68d5cc64-cb68-4275-9ede-9b062f7be070" # CentOS 6.5
$ FLAVOR="performance1-1"
$ TOKEN=`curl -s -XPOST https://identity.api.rackspacecloud.com/v2.0/tokens \
        -d'{"auth":{"RAX-KSKEY:apiKeyCredentials":{"username":"'$USERNAME'","apiKey":"'$API_KEY'"}}}' \
        -H"Content-type:application/json" | \
        python -c 'import sys,json;data=json.loads(sys.stdin.read());print data["access"]["token"]["id"]'`
  • Step #1: Create a CBS volume in DFW:
$ CBS_VOLUME_NAME="test-bfb-sata"
$ CBS_VOLUME_TYPE="SATA"  # or, "SSD"
$ CBS_VOLUME_SIZE=75 # i.e., 75GB, the smallest possible volume
$ curl -i -XPOST -H "X-Auth-Token: $TOKEN" \
       -H "Content-Type: application/json" -H "Accept: application/json" \
       "$CBS_ENDPOINT/volumes" \
       -d "{\"volume\": {\"display_name\": \"$CBS_VOLUME_NAME\", \"imageRef\": \"$IMAGE_ID\", \
            \"availability_zone\": null, \"volume_type\": \"$CBS_VOLUME_TYPE\", \
            \"display_description\": null, \"snapshot_id\": null, \"size\": $CBS_VOLUME_SIZE}}"

Watch the status of your CBS volume build until it goes from status "creating" to "active":

$ CBS_VOLUME_ID=aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee # From output of last command
$ curl -i -H "X-Auth-Token: $TOKEN" \
       -H "Content-Type: application/json" -H "Accept: application/json" \
       "$CBS_ENDPOINT/volumes/$CBS_VOLUME_ID"
  • Step #2: Boot a Cloud Server (in DFW) from the above CBS volume:
$ SERVER_ID=aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee # From output of last command
$ curl -i -H "X-Auth-Token: $TOKEN" \
       -H "Content-Type: application/json" -X POST -H "Accept: application/json" \
       "$SERVERS_ENDPOINT/v2/$ACCOUNT/servers/$SERVER_ID"

That's it! You now have a Cloud Server that has been booted from a CBS volume.

Links