Difference between revisions of "Rackspace API/Cloud Images"

From Christoph's Personal Wiki
Jump to: navigation, search
(New page: ==HOWTO: share images between Rackspace Cloud accounts== ===Export environment variables=== These are the shell variables we will use in all the subsequent steps (i.e., in our API calls):...)
(No difference)

Revision as of 13:36, 10 December 2014

HOWTO: share images between Rackspace Cloud accounts

Export environment variables

These are the shell variables we will use in all the subsequent steps (i.e., in our API calls):

$ TOKEN_PRODUCER=<Token_of_Producer>
$ TOKEN_CONSUMER=<Token_of_Consumer>
$ ACCOUNT_PRODUCER=000001
$ ACCOUNT_CONSUMER=000002
$ REGION=dfw
$ ENDPOINT_SERVERS_PRODUCER=https://${REGION}.servers.api.rackspacecloud.com/v2/${ACCOUNT_PRODUCER}
$ ENDPOINT_SERVERS_CONSUMER=https://${REGION}.servers.api.rackspacecloud.com/v2/${ACCOUNT_CONSUMER}
$ ENDPOINT_IMAGES_PRODUCER=https://${REGION}.images.api.rackspacecloud.com/v2/${ACCOUNT_PRODUCER}
$ ENDPOINT_IMAGES_CONSUMER=https://${REGION}.images.api.rackspacecloud.com/v2/${ACCOUNT_CONSUMER}

$ IMAGE_NAME_PRODUCER="my-saved-image-name"

Gather information on image to be shared

  • Get basic information on Producer's saved image (i.e., "my-saved-image-name"):
$ curl -H "X-Auth-Token: $TOKEN_PRODUCER" -H "Content-Type: application/json" \
       "${ENDPOINT_SERVERS_PRODUCER}/images?type=SNAPSHOT&name=${IMAGE_NAME_PRODUCER}" |\
       python -mjson.tool
$ IMAGE_ID_PRODUCER=fffff  # From "id" in above output
  • Get detailed information on Producer's saved image:
$ curl -s -H "X-Auth-Token: $TOKEN_PRODUCER" -H "Content-Type: application/json" \
       "${ENDPOINT_SERVERS_PRODUCER}/images/${IMAGE_ID_PRODUCER}" |\
       python -mjson.tool
  • Get all metadata associated with Producer's saved image:
$ curl -s -H "X-Auth-Token: $TOKEN_PRODUCER" -H "Content-Type: application/json" \
       "${ENDPOINT_IMAGES_PRODUCER}/images/${IMAGE_ID_PRODUCER}" |\
       python -mjson.tool
  • Get the members (aka "tenant_id"/account number) associated with Producer's saved image (if the image has never been shared, the "members" value will be empty):
$ curl -s -H "X-Auth-Token: $TOKEN_PRODUCER" -H "Content-Type: application/json" \
       "${ENDPOINT_IMAGES_PRODUCER}/images/${IMAGE_ID_PRODUCER}/members" |\
       python -mjson.tool
{
    "members": [],
    "schema": "/v2/schemas/members"
}

Share the image in question

$ curl -sXPOST -H "Content-Type: application/json" \
       -H "X-Auth-Token: $TOKEN_PRODUCER" \
       "${ENDPOINT_IMAGES_PRODUCER}/images/${IMAGE_ID_PRODUCER}/members" \
       -d "{\"member\":\"$ACCOUNT_CONSUMER\"}" |\
       python -mjson.tool

The image has now been shared to the consumer. However, the status of the share will be in "pending", as the API is waiting on the consumer to accept the shared image.


See also