Unleash the power of the NTNX-AVM – Move VM from one container to another container (AHV) with move_vm

This series describes the installation, configuration and usage of the NTNX-AVM. In addition the mostly used scripts will be explained in detail.

full course
  1. Nutanix automation VM ( NTNX-AVM ) goes online
  2. Unleash the power of the NTNX-AVM – daily_health_report and monthly_ncc_health
  3. Unleash the power of the NTNX-AVM – Import/Export/Migrate VMs to/from AHV
  4. Unleash the power of the NTNX-AVM – Move VM from one container to another container (AHV) with move_vm

This post is related to AHV only!!! Make sure a recent backup of the VM exist!

In the last weeks customers asked me how to move a VM from one AHV container to another AHV container on the same cluster. The answer is: “There is no PRISM/GUI option for this and the manual task is pretty difficult”. So i wrote a script called move_vm which I show in this post to simplify this.

But why should you move a VM?

There are several reasons for this.

  • container settings don’t fit
  • different containers for different organization units
  • DR/backup concepts based on containers
  • Automation based on containers
  • … and more

Example: Let’s say the customer started with two containers:

  1. ISO – just for templates and CD/DVD ISO images
  2. prod –  productions environment

Now he realizes that some of the server VMs would be great for compression but some are not. He used the best practices to figure out which server VMs would fit.

compression_bestpractices

For this case he created a new container called:

3 . prod_comp with active inline compression for SQL Server 2012 R2 VMs

Now he tried to move the VM from container prod to prod_comp and found that this does not work and asked me.

USE CASE: Move a VM from one AHV container to another AHV container to make use off inline compression for a several VMs!

I created a new container called prod_comp with inline compression in my Intel NUC environment.

container_prod_comp

Then I created a VM called “Move_VM_Test1” with different kind of disk devices and CD/DVD drives with all reside on the prod container.

move_vm_test1

Now I am using the tool move_vm which is installed on the NTNX-AVM to move the VM. The tool has several options which I list here.

Move a whole VM from container prod to prod_comp

In the first case the syntax is pretty simple to move the whole VM from prod to prod_comp. REMEMBER the source VM needs to be powered off before you are able to move it.

move_full_vm

overview_vms_double

You may noticed that there are two VMs now with the same name. I believe it makes sense to keep the old VM unless you are sure the new copy works.

You can use the option “–delete” to delete the source VM. The advantage is that the new network adapters will have the same MAC address then the source VM! 

 

Move just one vDisk/disk of the VM from container prod_comp back to prod

I renamed the new Move_VM_Test1 to Move_VM_Test2 for the next part.

Let’s say you would like to move just one vDisk from a container prod_comp back to prod because you found that inline compression makes no sense. An example maybe the “transaction log” vdisk of a MS SQL Server.

First we need to find out which vdisks exist and how the mapping looks like. This can be done with the “–list_mapping” option.

the output is:

which means that there are four vdisks and two CD/DVD drives. Let’s say we identified that the the second vdisk: “scsi.1” is the one we would like to move back to container prod. In this case we need to specify the whole mapping when calling the move_vm tool to only move the second vdisk. Copy and paste is the way to go!

The syntax is:

I only changed the prod_comp to prod for the scsi.1 vdisk!

move_vdisk

You may ask: “Why is the whole VM cloned and not only the vdisk?” Yep you are right. This would be the better way. This is how this tool works atm. This is more a copy then a move but it works and its pretty fast because only the vdisk “scsi.1” needs to be copied.

You could specify the option “–delete” the delete the source VM and to make sure the new network adapters get the same MAC address.

moved_vdisk

There we go.

For all the people who wants to know more, this is an overview how this tool works:

  1. Upload vDisk from source VM to image service. This is needed while a direct copy is not possible
  2. Create new VM
  3. Clone Images to Disks
  4. Add network
  5. Delete images