So we had a customer today that wanted to create a next generation cloud-server using a first generation server image. Since the first gen platform uses cloud files, it’s possible to do manually, downloading from cloud files , concatenating and untar to access the filesystem.
Like so;
cat receiverTar1.tar receivedTar2.tar >> alltars.tar
tar -itvf alltars.tar
Although I used on my mac:
tar -vxf alltars.tar
This gives us the VHD files extracted into an ‘image’ folder;
$ ls -al image/
total 79851760
drwxr-xr-x 6 adam9261 RACKSPACE\Domain Users 204 Apr 19 12:17 .
drwxr-xr-x 11 adam9261 RACKSPACE\Domain Users 374 Apr 19 11:47 ..
-rw-r--r-- 1 adam9261 RACKSPACE\Domain Users 40884003328 Jan 4 07:05 image.vhd
-rwxr-xr-x 1 adam9261 RACKSPACE\Domain Users 1581 Apr 19 12:15 import-container.sh
-rw-r--r-- 1 adam9261 RACKSPACE\Domain Users 8 Jan 4 07:05 manifest.ovf
-rw-r--r-- 1 adam9261 RACKSPACE\Domain Users 84480 Jan 4 07:05 snap.vhd
We are interested in the image.vhd file. Now lets upload it to cloud files to IMPORT it into Glance, which is what is used by the next generation platform to create a new server. The problem of course was that the first gen image format wasn’t compatible. Next gen builds need to retrieve the VHD image from glance.
Also, lets ensure we use Transfer-Encoding: chunked” as a host -H header. This tells Cloud Files that the .vhd exceeds 5G and it will create a multi-part manifest for us for the main file. Splitting it up for us into multiple objects spanned across 5Gig Files!
# Username used to login to control panel
USERNAME='mycloudusername'
# Find the APIKey in the 'account settings' part of the menu of the control panel
APIKEY='mycloudapikey'
# Find the image ID you'd like to make available on cloud files
CUSTOMER_ID=10001010
IMPORT_CF_ENDPOINT="https://storage101.lon3.clouddrive.com/v1/MossoCloudFS_50441c7a-dc22-4287-8e8c-b9844df"
# This section simply retrieves the TOKEN
TOKEN=`curl https://identity.api.rackspacecloud.com/v2.0/tokens -X POST -d '{ "auth":{"RAX-KSKEY:apiKeyCredentials": { "username":"'$USERNAME'", "apiKey": "'$APIKEY'" }} }' -H "Content-type: application/json" | python -mjson.tool | grep -A5 token | grep id | cut -d '"' -f4`
# Upload VHD
curl -X PUT -T image.vhd \
-H "X-Auth-Token: $TOKEN" \
-H "Transfer-Encoding: chunked" \
"$IMPORT_CF_ENDPOINT/import/image.vhd"
Update:
Something in curl transmission caused it to sadly, mess up. So I used swiftly instead.
$ swiftly put -i image.vhd import/image.vhd
The problem with swiftly was it didn’t like my .swiftly file in my ~ as should work 100% without problems, but it didn’t. With help of my friend Jake this is what I did, to get round that and set manually in the environment (as opposed to using the .swiftly file)
abull-mb:~ adam9261$ export SWIFTLY_AUTH_URL=https://identity.api.rackspacecloud.com/v2.0
abull-mb:~ adam9261$ export SWIFTLY_AUTH_USER=cloudusernamehere
abull-mb:~ adam9261$ export SWIFTLY_AUTH_KEY=apikeyhere
abull-mb:~ adam9261$ swiftly auth
Next stage import to glance
#!/bin/bash
# Username used to login to control panel
USERNAME='mycloudusername'
# Find the APIKey in the 'account settings' part of the menu of the control panel
APIKEY='mycloudapikey'
# Find the image ID you'd like to make available on cloud files
CUSTOMER_ID=10001010
IMPORT_CF_ENDPOINT="https://storage101.lon3.clouddrive.com/v1/MossoCloudFS_50441c7a-dc22-4287-8e8c-b6d76b237da"
IMPORT_IMAGE_ENDPOINT=https://LON.images.api.rackspacecloud.com/v2/$CUSTOMER_ID
# This section simply retrieves the TOKEN
TOKEN=`curl https://identity.api.rackspacecloud.com/v2.0/tokens -X POST -d '{ "auth":{"RAX-KSKEY:apiKeyCredentials": { "username":"'$USERNAME'", "apiKey": "'$APIKEY'" }} }' -H "Content-type: application/json" | python -mjson.tool | grep -A5 token | grep id | cut -d '"' -f4`
VHD-NOTES=TESTING-RACKSPACE-IMAGE-IMPORT
IMPORT_CONTAINER=import
curl -X POST "$IMPORT_IMAGE_ENDPOINT/tasks" \
-H "X-Auth-Token: $TOKEN" \
-H "Content-Type: application/json" \
-d "{\"type\":\"import\",\"input\":{\"image_properties\":{\"name\":\"$VHD_NOTES\"},\"import_from\":\"$IMPORT_CONTAINER/image.vhd\"}}" |\
python -mjson.tool
Please note that image.vhd is hardcoded into the curl import. Also see VHD-NOTES variable which is passed to the task. This is just to identify the image more easily.
Response:
{
"created_at": "2016-04-19T13:12:57Z",
"id": "ff7d8c09-9dd7-43ed-824f-338201681b12",
"input": {
"image_properties": {
"name": ""
},
"import_from": "import/image.vhd"
},
"message": "",
"owner": "10001010",
"result": null,
"schema": "/v2/schemas/task",
"self": "/v2/tasks/ff7d8c09-9dd7-43ed-815f-338201681ba7",
"status": "pending",
"type": "import",
"updated_at": "2016-04-19T13:12:57Z"
}
I then retrieved the Task details: (code not included yet). In this case I used pitchfork.cloudapi.co. A rackspace service that allows you to make API calls using a web frontend.
I was in a rush to get this done for the customer as soon as possible.
{
"status": "processing",
"created_at": "2016-04-19T13:12:57Z",
"updated_at": "2016-04-19T13:12:58Z",
"id": "ff7d8c09-9dd7-43ed-824f-338201681b12",
"result": null,
"owner": "10009158",
"input": {
"image_properties": {
"name": ""
},
"import_from": "import/image.vhd"
},
"message": "",
"type": "import",
"self": "/v2/tasks/ff7d8c09-9dd7-43ed-815f-338201681ba7",
"schema": "/v2/schemas/task"
}
We can now see that the status is processing. When it has completed, it will tell us whether it failed or not
After waiting 30 minutes or so:
{
"status": "success",
"created_at": "2016-04-19T13:12:57Z",
"updated_at": "2016-04-19T14:22:53Z",
"expires_at": "2016-04-21T14:22:53Z",
"id": "ff7d8c09-9dd7-43ed-815f-338201681ba7",
"result": {
"image_id": "826bbb51-0f83-4278-b0ad-702aba088aae"
},
"owner": "10009158",
"input": {
"image_properties": {
"name": ""
},
"import_from": "import/image.vhd"
},
"message": "",
"type": "import",
"self": "/v2/tasks/ff7d8c09-9dd7-43ed-815f-338201681ba7",
"schema": "/v2/schemas/task"
}
It worked!