Tuesday, February 25, 2014

OpenStack & VMWare VM Disk Migration

OpenStack & VMWare VM Disk Migration


This short tutorial shows a way to perform VM migration from an OpenStack infrastructure to a VMWare infrastructure, and vice-versa. By migration we do not mean hot on-the-fly migration of a VM, but rather VM disk migration. Please note that this is just one out of many procedures, if you have found something better please let us all know.

Migration from OpenStack to VMWare


Current versions of OpenStack do not allow to retrieve VM images with a container format (such as OVF or VMX formats). However it is possible to obtain their disk images, which is enough for us.

1. Obtain VM disk image from OpenStack infrastructure

It is usually placed in Glance image directory (for example /opt/stack/data/glance/images/). We assume the format is QEMU QCOW Image (v2). OpenStack Image Services (API v2.0) allow to get the VM disk image through an HTTP GET at v2/images/{image_id}/file .

You can also use glance client (see the annexe for further information on installation and version):

   $ glance -I <user> -K <pass> -T <tenant> -N <url>/v2.0 image-download --progress --file <vmImageFile> <imageId>

2. Convert vmdisk.qcow2 into a vmdisk.vmdk format (supported by VMWare)

   $ qemu-img convert -f qcow2 -O vmdk vmdisk.qcow2 vmdisk.vmdk

3. Create a vm.vmx container for vmdisk.vmdk

When creating vm.vmx metadata file, make sure the disk file vmdisk.vmdk is in the same directory. There are plenty of parameters VMWare allows you to set, you can start using these (you can see the documentation for more information):



config.version = "6"
memsize = "1024"
displayName = "vm"
scsi0.present = "true"
scsi0.sharedBus = "none"
scsi0.virtualDev = "lsilogic"
scsi0:0.present = "true"
scsi0:0.fileName = "vmdisk.vmdk"
scsi0:0.deviceType = "scsi-hardDisk"
virtualHW.productCompatibility = "hosted"

4. Import the VM image (vm.vmx + vmdisk.vmdk) into VMWare infrastructure

   $ ovftool --powerOn vm.vmx vi://<user>:<password>@<ESXi-server>/

That's all. You should see your new VM called "vm" (see the .vmx file, property displayName) booting.

Migration from VMWare to OpenStack


We will now do the opposite, take a VM from OpenStack and make it run on a VMWare infrastructure.

1. Obtain the OVF container file of the VM VMWare infrastructure

   $ ovftool --powerOffSource vi://<user>:<password>@<ESXi-server>/<vmName> vm.ovf

This will download the OVF file together with some other files, like the VMDK disk file. It usually has the name vm-disk1.vmdk .

2. Convert VM disk file into a QCOW2 format disk file (supported by OpenStack)

   $ qemu-img convert vm-disk1.vmdk -O qcow2 vm-disk1.qcow2

Note: use qemu-img v1.2 or newer to avoid a weird sector error. See the Annexe for further information on version and installation.

3. Import the QCOW2 disk image into Glance 

   $ glance -I <user> -K <pass> -T <tenant> -N <url/v2.0> image-create --name <newVmName> --disk-format=qcow2 --container-format=bare --file <srcVmImageFile>

4. Start the VM using the OpenStack API

Use Horizon (OpenStack web portal) to launch a VM using the just imported VM image.
You can also do it through command line using nova client:

   $ nova --os-username <user> --os-password <password> --os-tenant-name <tenant> --os-auth-url <url/v2.0> boot --image <imageId> --flavor <newVmFlavorId> <newVmName>

Annexe

Install glance client (v0.12.0.49)

   $ https://github.com/openstack/python-glanceclient
   $ cd python-glanceclient
   $ python setup.py install 
   $ sudo pip install pbr

Install nova client (v2.15.0.237)

   $ git clone https://github.com/openstack/python-novaclient.git
   $ cd python-novaclient/
   $ sudo python setup.py install

Install qemu (v1.2.0)

   $ sudo apt-get install libglib2.0-dev
   $ wget http://wiki.qemu.org/download/qemu-1.2.0.tar.bz2
   $ tar xfj qemu-1.2.0.tar.bz2
   $ cd qemu-1.2.0
   $ ./configure && make qemu-img

Some other references

Here there is a very interesting article I found about VM image containers and disk formats.

That's all folks. 

No comments:

Post a Comment