Tuesday, January 13, 2009

Recovering Virtual Machine Templates after Re-Installing VMware Virtual Center

If you have ESX servers managed by VMware Virtual Center chances are you've created templates of standard types of machines so deploying a new one becomes simpler. These templates are such time-savers that I tend to keep tweaking them with every new requirement until I have the perfect pristine CentOS or Win2k3 or FreeBSD host. Deploying a new virtual machine from a template is a cinch and the deployed machines always look identical - at least until you start customizing them. This means you can create scripts that run against a truly standard configuration and know that it will work the same way every time but I digress. This post is about what happens when you have to re-install VMware Virtual Center. This is something that I found two solutions for which both work well. However, the second solution is far simpler and less time-consuming.

The Easy Way
The first solution relies on the ability of VMware Infrastructure Client to convert a Template into a Virtual Machine and back. Since all virtual machines stored on ESX servers managed by a new instance of Virtual Center are automatically recognized and properly populated in the Virtual Infrastrucure Client, make sure you name every template to reflect that it's a template by e.g. putting the word "Template" somewhere in its name, etc.
  1. Switch your Virtual Infrastructure Client to display both virtual machines and templates by using the keyboard shortcut Ctrl-Shift-V or by clicking on dropdown associated with the large "Inventory" drop down in the top toolbar and choosing "Virtual Machines and Templates".
  2. Right-click on each template and choose "Convert to Virtual Machine".
  3. Once you've converted all your templates to virtual machines you can re-install Virtual Center.
  4. Now re-connect to the new instance of Virtual Center and you'll see all your templates as virtual machines.
  5. Right-click on each virtual machine that used to be a template (see where the naming comes in?) and click on "Convert to Template"
Voila! You now have your templates back. It does take some time to convert a template to a VM and back but it works.

The Elegant Way
This method doesn't require you to convert your templates to virtual machines and back. Just re-install your instance of Virtual Center and you will notice all your templates disappear the next time you connect to the new Virtual Center using your Virtual Infrastructure Client. Follow these steps to bring them back:
  1. Switch your Virtual Infrastructure Client to display your datastores by using the keyboard shortcut Ctrl-Shift-D or by clicking on dropdown associated with the large "Inventory" drop down in the top toolbar and choosing "Datastores".
  2. Click on a group and then a datastore and in the right detail panel click on "Browse Datastore...". This should bring up a window that will allow you to browse that datastore. Each virtual machine and template will have its own directory in this datastore.
  3. Click on a directory named after one of your templates. The right panel will change to show you all the files in that directory.
  4. Right click on the only file of type "Template VM" and click on "Add to Inventory".
  5. In the dialog box that pops up, give the template a name (presumably the same name as it currently has) and choose its location (presumably the same group it's in now).
  6. In the next dialog box choose the host to store the template on. This should be the same ESX server whose datastore you're browsing.
  7. After validating the template/vm it will present the last dialog of the wizard with the details of your "VM". Click "Finish" and you're done.
  8. Close the data store browser and change your Virtual Infrastructure Client to "Virtual Machines and Templates" mode using Ctrl-Shift-V or by clicking on Inventory and choosing "Virtual Machines and Templates" and you'll see the template back in the inventory!
Enjoy!

No comments:

Post a Comment