4

Is it possible to determine the name of the VMware host (ESX or ESXi) that my guest resides in, from within the guest itself?

I would expect this to be possible via VMware Tools, but am not sure where to look.

warren
  • 17,829
  • 23
  • 82
  • 134
  • Is there a reason you wouldn't just take a look in vCenter? If you click on the server, the host is listed in the Status tab... – Jes Sep 16 '10 at 13:38
  • @Jes - I'm looking to do this from a script – warren Sep 16 '10 at 15:07
  • Why would you want to do that? Just curious. – ThatGraemeGuy Sep 16 '10 at 15:51
  • in the context of a large, managed environment, it would be nice to be able to run a script on some schedule that would report to syslog or similar the host that it is resident upon – warren Sep 17 '10 at 16:07
  • @Graeme Donaldson - to expand on my previous comment, when VMs move between hosts due to vMotion or because migration/upgrading of the underlying hardware of hypervisor is coming along, knowing where a given VM is currently running would be nice... but it appears this is [sadly] non-trivial (at least for now) – warren Oct 20 '10 at 15:21

4 Answers4

1

You can't do it without first editing the VMX file.

Here is the stackoverflow answer to the same question

JakeRobinson
  • 2,886
  • 17
  • 26
  • that's for Workstation, and I'm looking at this form an ESX/ESXi perspective (clarifying my question) – warren Sep 16 '10 at 15:08
  • 2
    The same limitation applies - getting information about the Hypervisor from within a guest is generally not easy, unless you already know the identity of the Hypervisor and can talk to it over the network. – Helvick Sep 16 '10 at 15:26
  • It doesn't matter if its workstation, ESX, or any other VMware product. It's a security setting that has to be disabled. – JakeRobinson Sep 16 '10 at 18:59
0

There are a few powershell scripts that will let you do this. Alternatively.. open http://yourESXaddress and check out the api For a quick export that you could parse by script use your script to pull the contents of http://ESXIPAddress/mob/ which lists the resources managed by that ESX host

0

I think there are probably any number of ways to do this, and can think of two off the bat: One would be to install ViX in the guest, connect to the host without specifying the hostname, (Google "ViX reference" then see "common tasks") then use Vix_CopyFileFromHostToGuest() to copy the file /etc/vmware/esx.conf. Another would be to create some sort of network connection from the guest to the host (I used ssh but if you don't know the hostname or IP you could still do the ViX connection thing as above and dispatch a job that takes a while) and then say "netstat -a" in the guest. The netstat output will contain the hostname, if it is resolvable.

  • 1
    These are pretty kludgey solutions and the later assumes you know who the host is, which is exactly what is being looked for. If you'd looked at previous answers you'd see that the ESX host provides an API that you can connect to that introduces itself. It's always best to use provided features before hacking your own! – Caleb Oct 22 '10 at 08:27
-1

From a Linux guest, network routing information seems to yield the host information:

netif=$(arp -a | grep gateway | awk '{print $7}') SERVERIP=$(routel | grep $netif | grep -v gateway | grep -v default | grep -v broadcast | grep local | grep host | awk '{print $1}') VI_SERVER=$(host $SERVERIP | awk '{print $5}' | awk -F. '{print $1}') echo "This VM host is $SERVERIP, $VI_SERVER"

Seems to give the correct VM host name and IP address for several hosts with Linux VMs.