Highlighted
Enthusiast
Enthusiast

how do I find out which host a vm is running on?

I am using vmware-cmd.pl to revert a snapshot but the command requires me to know the host that the virutal machine is currently on. My virtual machines can be on a number of hosts due to DRS. Is there a command that I can use to query virtual center to find out what host a VM is on and then execute the revertsnapshot command?

Currently I use this command:

vmware-cmd.pl -H hqvcenter01 -T esxhost01 /vmfs/volumes/4880d859-971e29ee-d42f-001e0b5dbc48/RemoteCLITest/RemoteCLITest.vmx revertsnapshot

This requires me to know which host "RemoteCLITest.vmx" lives on.

0 Kudos
3 Replies
Highlighted
Champion
Champion

Not sure about with CLI, but if you look at the VM in the vCenter client, it's one of the fields listed under "General". That's probably the easiest way to see which host it's on at that moment.

VCP4

Hosted Systems Engineer III (VMware environment) Making (forging) blades again
0 Kudos
Highlighted
Enthusiast
Enthusiast

I want this script to run daily so I don't want to have to look in virtual center each day to change the script as it moves hosts. Another option is to just set a rule in DRS but I find that not ideal due to host maintenance that needs to occur.

0 Kudos
Highlighted
Community Manager
Community Manager

There's an even better way than using the default vCLI's commands (esxcfg-*,etc) which generally applies to a specific system you're connecting to and performing an operation, it's not aware of vCenter and where each host or VM lives. It's the way they were written and you can easily write a loop to go through n-hosts to perform n-operations.

The API in which it uses however can speak to an individual ESX(i) host or to vCenter and that is what you're after. Many user's aren't aware that with the vCLI, there are additional utilities that are bundled which work with both individual ESX(i) host and vCenter known as the vSpher SDK for Perl Utilities - http://www.vmware.com/support/developer/viperltoolkit/viperl40/doc/vsperl_util_index.html

What you'll want to use is vmsnapshot.pl which allows you to connect to your vCenter and all you need to do is provide the name of the VM and snapshot name and it'll figure out exactly where it is and perform the operation. This is the same for all the other type of operations defined in the other canned scripts. This way, you don't need to worry about DRS, vMotion, etc. vCenter knows exactly where a given host and/or VM to perform the operation. This will also save you time from querying every single host to find your VM.

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Community

If you find this information useful, please award points for "correct" or "helpful".

0 Kudos