How to create a cloud server using cloud API.
Solution
A small script available at gitub [1] that uses available cloud API to login to the Rackspace cloud infrastructure. After login it issues necessary create request and creates a new cloud server. At the end prints the result on stdout.
Demonstration
- Standard output
# python rackspace_cloudserver.py -u user -k key run creating new cloud server with a name: cstest1343077883 { "server": { "status": "BUILD", "hostId": "50a21504e046275fa53877dc937ceab6", "name": "cstest1343077883", "adminPass": "KnB1Cu7t4cstest1343077883", "metadata": {}, "imageId": 112, "progress": 0, "flavorId": 1, "id": 10196007, "addresses": { "public": [ "5.79.1.17" ], "private": [ "10.178.4.241" ] } } }
- Verbose output
# python rackspace_cloudserver.py -u user -k key -v run debug[ 1]: user:key: key; debug[ 1]: http request lon.auth.api.rackspacecloud.com GET /v1.0 headers: X-Auth-Key: 391....aebe1 X-Auth-User: user debug[ 1]: http response 204 No Content headers content-length: 0 x-server-management-url: https://lon.servers.api.rackspacecloud.com/v1.0/10001641 x-storage-token: 7e901...67a vary: X-Auth-Token,X-Auth-Key,X-Storage-User,X-Storage-Pass x-cdn-management-url: https://cdn3.clouddrive.com/v1/MossoCloudFS_c99f3ebf-f27d-4933-94b7-9e9ebf2bc7cd server: Apache/2.2.3 (Red Hat) connection: Keep-Alive cache-control: s-maxage=85050 date: Mon, 23 Jul 2012 20:59:40 GMT x-storage-url: https://storage101.lon3.clouddrive.com/v1/MossoCloudFS_c99f3ebf-f27d-4933-94b7-9e9ebf2bc7cd x-auth-token: 7e90....1bc67a content-type: text/xml debug[ 1]: read 0 from the server: creating new cloud server with a name: cstest1343077180 debug[ 1]: http request lon.servers.api.rackspacecloud.com POST /v1.0/10001641/servers headers: Content-Type: application/json X-Auth-Token: 7e901...bc67a body: {"server": {"flavorId": 1, "name": "cstest1343077180", "imageId": 112}} debug[ 1]: http response 202 Accepted headers content-length: 272 x-varnish: 1662239131 age: 0 vary: Accept, Accept-Encoding, X-Auth-Token server: Apache-Coyote/1.1 connection: keep-alive via: 1.1 varnish cache-control: no-cache date: Mon, 23 Jul 2012 20:59:45 GMT content-type: application/json debug[ 1]: read 272 from the server: { "server": { "status": "BUILD", "hostId": "155a42778c64cf881c41ae5dc8a8bd0c", "name": "cstest1343077180", "adminPass": "4KUt5u3oXcstest1343077180", "metadata": {}, "imageId": 112, "progress": 0, "flavorId": 1, "id": 10195995, "addresses": { "public": [ "5.79.1.129" ], "private": [ "10.178.18.97" ] } } }
References
[1] https://github.com/rtomaszewski/experiments/blob/master/rackspace_cloudserver.py
No comments:
Post a Comment