Quick Migration for VMware

Earlier this year VMware released the VMware Infrastructure Toolkit (for Windows). This was a new PowerShell interface for VMware Infrastructure 3. I’m a big fan of the power and simplicity of PowerShell so I thought I’d try to create something with the script and show it off during my talk at VMworld on Deploying VMware in a Microsoft Shop. The question is what do I create? Well, there has been some great debate of Microsoft’s Quick Migration and VMware’s VMotion and are they equal or not, do they solve the same problems, etc. This post isn’t to go back into that debate. One of the things that was also brought up over and over again in the debate was the fact that Quick Migration was free and came with Hyper-V since it was based on Microsoft Clustering whereas VMware VMotion was only available in the most expensive Enterprise SKU of VMware Infrastructure. So there it was – I need to create Quick Migration for the lower priced and free VMware solutions. I went off, built my little script, and showed it off at VMworld. There was a GREAT response to it so I’m posting it here for others to use or improve upon however you see fit.

The script works just like Microsoft Quick Migration – the virtual disk is stored on shared storage, the VM is suspended to disk, and the VM is then resumed on the destination. Presto! Here’s a quick video:

To set this up in your environment you’ll need a few things:

  1. 2 VMware Infrastructure 3 hosts
  2. Windows PowerShell (and all of the pre-requirements for that if needed)
  3. VMware Infrastructure Toolkit (for Windows)
  4. The VM Migrator script from me
  5. A VM you want to migrate – it doesn’t matter what the guest OS is

Once you’ve got all of that you’re ready to go. Assuming you have Microsoft PowerShell installed and the VMware Toolkit installed on top of that you should be ready to run the script. PowerShell has some built-in security so you might have to either (a) answer yes when it prompts you to run unsigned scripts, (b) sign this script and make it yours, or (c) Set-ExecutionPolicy unrestricted. After you’ve got all of that sorted out just run the script by opening a new PowerShell window, changing to the path of the file, and running it using ./vmmigrator-1.0.ps1. The script will prompt you for the VirtualCenter address and an appropriate username and password to connect to it. You’ll next prompted for which VM you want to migrate and where you want to migrate it to. The script does some rudimentary checking for network, datastore, and connected devices before it will let you migrate.

Some last minute notes:

  • I’m not a developer or scripter by trade. This thing can probably be improved a lot. Feel free to do just that.
  • You can post the script or your modifications wherever you want. I just ask for a courtesy link back to here as well.
  • Unfortunately the free ESXi has a VERY limited API set enabled in the current 3.5 U2 release. This script won’t work with it. I’ve brought this to the product manager’s attention and I’m hoping we can open the API set up to everything shortly. Not really sure why it was restricted in the first place. For now you’ll need at least the Foundation SKU of Virtual Infrastructure.

Some future things I’d like to do with this:

  • I say the script requires shared storage right now but actually it doesn’t. The PowerShell cmdlet that does the migration actually does a “Relocate VM” which will move the storage for the VM from one internal datastore to another. That process is SLOW but it does work. Right now the script is hard coded to keep things on the same datastore. With some slight modifications it can do a Quick Migration with 2 standalone hosts. I’ll probably make a version 2 that will do that.
  • I’d like to integrate this into PowerGUI so you can just right-click on a VM in Virtual Center and run this script which will do a Quick Migration to a host of your choice. That project is a little further down my to-do list.

I hope you enjoy the script. Feel free to leave comments to let me know if this is useful or not.

Source: http://mikedatl.typepad.com/mikedvirtualization/2008/10/quick-migration.html