How do I copy a VM to another Project or Contract?

Currently, there is no one-step-process for copying or transferring a VM into another project  within the same contract or different contract. In order to do this, first you must shut down the VM and then clone the VM’s  system drive and any additional data drives separately.

This cloning process will then create a private image of each cloned disk, storing each image within the Portal under ‘Project | Compute | Image menu’. See the below steps:

Clone System and Data Disks

1. Setup and declare the required variables :

VOLUME_ID=

FORCE=true

DISK_FORMAT=raw

CONTAINER_FORMAT=bare

NAME=

Run the following command to Image the disk:

Repeat the above for each disk. The VM can be powered back on, once the above command has been run for all disks associated with the VM.

CAUTION: Cloning of a VM that has had the default partitions altered in anyway, may corrupt the image, preventing any VM deployed using it from booting correctly.

Publish Images between Projects

Once the status of each disk with ‘List Storage’ screen has changed from “Upload” to “in-use”, you can then begin the process of making that/those image(s) available to other projects. See the below steps:

1. Setup and declare the required variables :

MEMBER=

STATUS=accepted

IMAGE_ID=

2. Scope to Source Project and get your API token

3. Run the following command to make the image available to the destination project:

4. Scope to Destination Project and get your API token

5. Run the following command to accept the image from the source project

Repeat the above for each image required.

Deploying a VM from private Image

A VM can then be created as normal, using this system disk image, but before deploying a VM in the target project, I would recommend waiting a while. It seems that if you try to deploy a VM too quickly, that it remains with a status of ‘building’ and eventually results in an error. If this happens to you, simply delete and try and redeploy. I will update this blog, once I have a response from a support query I have raised.

Each data disk first needs to be added as storage, specifying the ‘Storage Source’ as ‘Image’, then choosing the appropriate image in the ‘The volume will be created from an image’ drop down box.

The storage can then be attached to a VM as normal, under the Storage ‘Action | Edit Connection’ menu

A Word on Deletion of an Image

It is important to note that the image of the cloned VM is only stored once per contract, having the same ID across projects. If you delete the image from the source project, you will also remove it from all target projects also.

An image cannot currently be deleted using the portal and can only be deleted using the API.

The following command can be used to delete an image

curl -X DELETE $COMPUTE/v2/$PROJECT_ID/images/<IMAGE ID> -H “X-Auth-Token: $OS_AUTH_TOKEN” -H “Content-Type: application/json”

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s