10
RES Wisdom and VMware Virtual Center
The content of this post is a bit more complicated than usual, but if you need to implement a change inside a VM in a vCenter environment with vMotion and DRS, I believe it’s worth the read.
In RES Wisdom 2009 you can create a connector to an ESX(i) host to manipulate VMs. This way, you can create a snapshot before you apply a change inside a VM (see:
http://blog.ressoftware.com/?p=55).
So your Run Book could look like this:
Run Book (Default behaviour: stop on error)
Module 1:
Get-VM-Host (The PowerShell Script)
Create Snapshot (Using the ESX environment variabele)
Module 2: (only exception: continue on error)
Implement Change on VM (e.g. install SP2 on 2003 server)
Module 3: (on error condition: execute module on previous error)
Get-VM-Host (The PowerShell Script again because VM may have moved)
Revert to Snapshot
Module 4:
Get-VM-Host (The PowerShell Script)
Delete Snapshot
Note:
To get all this to work, we had to change something in the way we retrieve environment variables, so you need at least RES Wisdom 2009 SR1.
This poses a challenge if you use vMotion, because with vMotion you’re never sure on which ESX host your VM resides: the VM can move around while it’s running. Since Wisdom does not support a connector to vCenter (yet), I had to figure out a way to identify a VM amongst multiple ESX hosts.
What I did is install PowerShell (http://www.microsoft.com/PowerShell) and the VI toolkit (http://www.vmware.com/download/) on the vCenter server. After some testing I found that with only 1 line of PowerShell code I could retrieve the ESX host for a specific VM:
(Get-VM “VM name”).Host.Name
The next problem was to get it from PowerShell into a Wisdom job. I found the best way to do this is to put the hostname in an environment variable and use this variable as the name for the connector. Since we have to use a system-wide variable, we need to do this the .NET way otherwise the variable will be gone when the PowerShell job ends. Using Wisdom variables the complete script looks like this:
Add-PSSnapin VMware.VimAutomation.Core
Connect-VIServer $[VirtualCenter] -User “$[VCUser]” -Password “$[VCPassword]”
“”[Environment]::SetEnvironmentVariable(“ESXHost”, (GET-VM “$[VMname]“).Host.Name, “Machine”)
After running this script, the Virtual Center server has an ESXhost variable that contains the machine host with the VM. If you put this task in every module before every VMware task, you can now build the “Controlled change on VM” to work in a vCenter environment! Of course all possible ESX hosts need to have a valid connector license.