Difference between revisions of "Rackspace API"

From Christoph's Personal Wiki
Jump to: navigation, search
(Cloud Servers)
Line 29: Line 29:
  
 
==Cloud Servers==
 
==Cloud Servers==
* List all of the NextGen servers on your account for a given region:
+
* List all of the ''NextGen'' servers on your account for a given region:
  account=$MYRAXACCOUNT
+
  account=$MYRAXACCOUNT; region=dfw
region=dfw
+
 
  curl -XGET <nowiki>https://$region.servers.api.rackspacecloud.com/v2/$account/servers</nowiki> \
 
  curl -XGET <nowiki>https://$region.servers.api.rackspacecloud.com/v2/$account/servers</nowiki> \
 
       -H "X-Auth-Token: $TOKEN" \
 
       -H "X-Auth-Token: $TOKEN" \
 
       -H "Accept: application/json" | python -m json.tool
 
       -H "Accept: application/json" | python -m json.tool
  
* List all of the FirstGen servers on your account (regardless of region):
+
* List all of the ''FirstGen'' servers on your account (regardless of region):
 
  account=$MYRAXACCOUNT
 
  account=$MYRAXACCOUNT
 
  curl -s <nowiki>https://servers.api.rackspacecloud.com/v1.0/$account/servers</nowiki> \
 
  curl -s <nowiki>https://servers.api.rackspacecloud.com/v1.0/$account/servers</nowiki> \

Revision as of 13:18, 28 October 2013

This article will be a somewhat random assortment of API calls to various Rackspace services. I plan to organize this article and add nearly all possible calls. Most of the API calls will be made using `curl` commands, but other resources will be used as well.

Authentication

For every API call it is first necessary to obtain an authenticated token. These tokens are valid for 24 hours and you must re-authenticate if it has expired. To authenticate, you only need your Rackspace account username ($MYRAXUSERNAME) and your API Key ($MYRAXAPIKEY).

  • Simple authentication (this should return, among other things, an "X-Auth-Token"):
curl -D - -H "X-Auth-Key: $MYRAXAPIKEY" \
     -H "X-Auth-User: $MYRAXUSERNAME" \
     -H "Content-Type: application/json" \
     -H "Accept: application/json" \
     https://identity.api.rackspacecloud.com/v1.0
  • Authenticate and receive a full listing of API endpoints (for all of the Rackspace services active on your account):
curl -X POST https://identity.api.rackspacecloud.com/v2.0/tokens \
     -d '{ "auth":{ "RAX-KSKEY:apiKeyCredentials":{ "username":"$MYRAXUSERNAME", "apiKey":"'$MYRAXAPIKEY'" } } }' \
     -H "Content-type: application/json"
  • Authenticate the same way as above, but use compression during the send/receive:
curl -i -X POST \
     -H 'Host: identity.api.rackspacecloud.com' \
     -H 'Accept-Encoding: gzip,deflate' \
     -H 'X-LC-Request-ID: 16491440' \
     -H 'Content-Type: application/json; charset=UTF-8' \
     -H 'Content-Length: 119' \
     -H 'Accept: application/json' \
     -H 'User-Agent: libcloud/0.13.0 (Rackspace Monitoring)' \
     --data-binary '{"auth": {"RAX-KSKEY:apiKeyCredentials": {"username": "$MYRAXUSERNAME", "apiKey": "$MYRAXAPIKEY"}}}' \
     --compress https://identity.api.rackspacecloud.com:443/v2.0/tokens

Cloud Servers

  • List all of the NextGen servers on your account for a given region:
account=$MYRAXACCOUNT; region=dfw
curl -XGET https://$region.servers.api.rackspacecloud.com/v2/$account/servers \
     -H "X-Auth-Token: $TOKEN" \
     -H "Accept: application/json" | python -m json.tool
  • List all of the FirstGen servers on your account (regardless of region):
account=$MYRAXACCOUNT
curl -s https://servers.api.rackspacecloud.com/v1.0/$account/servers \
     -H "X-Auth-Token: $TOKEN" | python -m json.tool

External links