#Curl and the Rackspace Cloud
This provides a quick introduction of how to use curl
with the Rackspace Cloud.
Before you can start issuing commands using curl
you will need to authenticate to the Rackspace Cloud. The authentication process provides you with an authentication token and as well as a service catalog.
The authentication token is a temporary token that associates your account with your requests. The service catalog is a list of service endpoints for your account.
To authenticate with the Rackspace Cloud, execute the following curl
command substituting USERNAME and API_KEY with the appropriate values:
curl -s https://identity.api.rackspacecloud.com/v2.0/tokens -X 'POST' \
-d '{"auth":{"RAX-KSKEY:apiKeyCredentials":{"username":"USERNAME", "apiKey":"API_KEY"}}}' \
-H "Content-Type: application/json" | python -m json.tool
This command should return a response similar to the following:
{
"access": {
"serviceCatalog": [
{
"endpoints": [
{
"internalURL": "https://snet-storage101.dfw1.clouddrive.com/v1/MossoCloudFS_XXXXXXX",
"publicURL": "https://storage101.dfw1.clouddrive.com/v1/MossoCloudFS_XXXXXXX",
"region": "DFW",
"tenantId": "MossoCloudFS_XXXXXXX"
},
{
"internalURL": "https://snet-storage101.ord1.clouddrive.com/v1/MossoCloudFS_XXXXXXX",
"publicURL": "https://storage101.ord1.clouddrive.com/v1/MossoCloudFS_XXXXXXX",
"region": "ORD",
"tenantId": "MossoCloudFS_XXXXXXX"
}
],
"name": "cloudFiles",
"type": "object-store"
},
{
"endpoints": [
{
"publicURL": "https://cdn1.clouddrive.com/v1/MossoCloudFS_XXXXXXX",
"region": "DFW",
"tenantId": "MossoCloudFS_XXXXXXX"
},
{
"publicURL": "https://cdn2.clouddrive.com/v1/MossoCloudFS_XXXXXXX",
"region": "ORD",
"tenantId": "MossoCloudFS_XXXXXXX"
}
],
"name": "cloudFilesCDN",
"type": "rax:object-cdn"
},
{
"endpoints": [
{
"publicURL": "https://ord.blockstorage.api.rackspacecloud.com/v1/XXXXXX",
"region": "ORD",
"tenantId": "XXXXXX"
},
{
"publicURL": "https://dfw.blockstorage.api.rackspacecloud.com/v1/XXXXXX",
"region": "DFW",
"tenantId": "XXXXXX"
}
],
"name": "cloudBlockStorage",
"type": "volume"
},
{
"endpoints": [
{
"publicURL": "https://dfw.databases.api.rackspacecloud.com/v1.0/XXXXXX",
"region": "DFW",
"tenantId": "XXXXXX"
},
{
"publicURL": "https://ord.databases.api.rackspacecloud.com/v1.0/XXXXXX",
"region": "ORD",
"tenantId": "XXXXXX"
}
],
"name": "cloudDatabases",
"type": "rax:database"
},
{
"endpoints": [
{
"publicURL": "https://ord.loadbalancers.api.rackspacecloud.com/v1.0/XXXXXX",
"region": "ORD",
"tenantId": "XXXXXX"
},
{
"publicURL": "https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/XXXXXX",
"region": "DFW",
"tenantId": "XXXXXX"
}
],
"name": "cloudLoadBalancers",
"type": "rax:load-balancer"
},
{
"endpoints": [
{
"publicURL": "https://ord.servers.api.rackspacecloud.com/v2/XXXXXX",
"region": "ORD",
"tenantId": "XXXXXX",
"versionId": "2",
"versionInfo": "https://ord.servers.api.rackspacecloud.com/v2",
"versionList": "https://ord.servers.api.rackspacecloud.com/"
},
{
"publicURL": "https://dfw.servers.api.rackspacecloud.com/v2/XXXXXX",
"region": "DFW",
"tenantId": "XXXXXX",
"versionId": "2",
"versionInfo": "https://dfw.servers.api.rackspacecloud.com/v2",
"versionList": "https://dfw.servers.api.rackspacecloud.com/"
}
],
"name": "cloudServersOpenStack",
"type": "compute"
},
{
"endpoints": [
{
"publicURL": "https://backup.api.rackspacecloud.com/v1.0/XXXXXX",
"tenantId": "XXXXXX"
}
],
"name": "cloudBackup",
"type": "rax:backup"
},
{
"endpoints": [
{
"publicURL": "https://dns.api.rackspacecloud.com/v1.0/XXXXXX",
"tenantId": "XXXXXX"
}
],
"name": "cloudDNS",
"type": "rax:dns"
},
{
"endpoints": [
{
"publicURL": "https://monitoring.api.rackspacecloud.com/v1.0/XXXXXX",
"tenantId": "XXXXXX"
}
],
"name": "cloudMonitoring",
"type": "rax:monitor"
},
{
"endpoints": [
{
"publicURL": "https://servers.api.rackspacecloud.com/v1.0/XXXXXX",
"tenantId": "XXXXXX",
"versionId": "1.0",
"versionInfo": "https://servers.api.rackspacecloud.com/v1.0",
"versionList": "https://servers.api.rackspacecloud.com/"
}
],
"name": "cloudServers",
"type": "compute"
}
],
"token": {
"expires": "2013-06-13T10:47:20.430-05:00",
"id": "AUTH_TOKEN",
"tenant": {
"id": "XXXXXX",
"name": "XXXXXX"
}
},
"user": {
"RAX-AUTH:defaultRegion": "DFW",
"id": "XXXXX",
"name": "USERNAME",
"roles": [
{
"description": "A Role that allows a user access to keystone Service methods",
"id": "5",
"name": "object-store:default",
"tenantId": "MossoCloudFS_XXXXXXX"
},
{
"description": "A Role that allows a user access to keystone Service methods",
"id": "6",
"name": "compute:default",
"tenantId": "XXXXXX"
},
{
"description": "User Admin Role.",
"id": "3",
"name": "identity:user-admin"
}
]
}
}
}
The authentication token can be found in the following section and is denoted here by the word AUTH_TOKEN:
"token": {
"expires": "2013-06-13T10:47:20.430-05:00",
"id": "AUTH_TOKEN",
"tenant": {
"id": "XXXXXX",
"name": "XXXXXX"
}
},
To find the service endpoint locate the service you are interested in and select the endpoint for the approprate region.
For example, if you wanted to use Cloud Servers this is the approprate section:
{
"endpoints": [
{
"publicURL": "https://ord.servers.api.rackspacecloud.com/v2/XXXXXX",
"region": "ORD",
"tenantId": "XXXXXX",
"versionId": "2",
"versionInfo": "https://ord.servers.api.rackspacecloud.com/v2",
"versionList": "https://ord.servers.api.rackspacecloud.com/"
},
{
"publicURL": "https://dfw.servers.api.rackspacecloud.com/v2/XXXXXX",
"region": "DFW",
"tenantId": "XXXXXX",
"versionId": "2",
"versionInfo": "https://dfw.servers.api.rackspacecloud.com/v2",
"versionList": "https://dfw.servers.api.rackspacecloud.com/"
}
],
"name": "cloudServersOpenStack",
"type": "compute"
},
In order to use ORD you would select the following endpoint:
https://ord.servers.api.rackspacecloud.com/v2/XXXXXX
With the authentication token and the endpoint obtained in the Authenticate section, we are now ready to use the Rackspace Cloud.
We will first need to find the approprate URI to add to the service endpoint for your desired action. In this example we want to list servers. You can find the REST documentation for listing servers here.
This page shows two different methods to list servers.
Verb | URI | Description |
---|---|---|
GET | /servers?image=imageId& flavor=flavorId& name=serverName& status=serverStatus& marker=markerID& limit=int& changes-since=dateTime& RAX-SI:image_schedule=boolean | Lists IDs, names, and links for all servers. |
GET | /servers/detail?image=imageId& flavor=flavorId& name=serverName& status=serverStatus& marker=markerID& limit=int& changes-since=dateTime& RAX-SI:image_schedule=boolean | Lists all details for all servers. |
I am going to opt for first URI, /servers
, as I am interested in just obtaining the server names.
The URL used by curl
will be our service endpoint plus the URI as follows:
https://ord.servers.api.rackspacecloud.com/v2/XXXXXX/servers"
We will also need to pass our authentication token as a header with the name X-Auth-Token
.
Putting these together you would get the following command:
curl -s "https://ord.servers.api.rackspacecloud.com/v2/XXXXXX/servers" \
-H "X-Auth-Token:AUTHENTICATION_TOKEN" | python -m json.tool
Our response shoudl be similar to the following:
{
"servers": [
{
"id": "cab21010-96c1-475c-9e17-c7b729452569",
"links": [
{
"href": "https://ord.servers.api.rackspacecloud.com/v2/XXXXX/servers/cab21010-96c1-475c-9e17-c7b729452569",
"rel": "self"
},
{
"href": "https://ord.servers.api.rackspacecloud.com/XXXXX/servers/cab21010-96c1-475c-9e17-c7b729452569",
"rel": "bookmark"
}
],
"name": "my-server"
}
]
}
##Additional Resources