VMware {code} Community
Dick_Murray
Contributor
Contributor

Get ESX VM name from within the Guest OS.

Is it possible to get the ESX 3.0.2 VM name from within the Guest XP OS?

I have a VBScript which configures the IP address based on the Guest OS hostname, e.g. "test-1-1" becomes "192.168.1.1".

What I would like to do is query the ESX VM and use this to configure the host IP address.

Tags (1)
Reply
0 Kudos
7 Replies
borism
Contributor
Contributor

It's possible, but a little bit complicated. Requires coding...

Simple scenarion

Basically, through VI SDK you can retrire the IP, hostname and VM name based on Guest IP or Hostname.

Best Regards,

Boris

_t
Contributor
Contributor

i don't fully understand your question because you wrote that you want to query the VM name from within the Guest OS,

but want to use it to configure the host IP address.

If you would like to configure the guest's IP address, you could query the GuestInfo variables from within the Guest OS by VMware Tools:

VMwareService.exe -cmd "info-get guestinfo.myvariablename"

and set this variable on the host-side by adding the following line at the bottom of your vmx-file:

guestinfo.myvariablename = "test-1-1"

or pass it to the virtual machine startup by command line arguments (see documentation).

Dick_Murray
Contributor
Contributor

Yes, it does seem odd what I want to achieve.

If I deploy a Guest OS with an ESX name of "test-1-1" I want the Guest OS IP address to be "192.168.1.1". Simply, the two numeric identifiers at the end of the name become the last two octets of the Guest OS IP address.

Your suggestion is good as I already create the VMX files using a script based on a two counts, so adding an extra line with the detail is good.

As a background I have a script which creates multiple VMX files with non persistent disks which point to a readonly base VMX and VMDK. At startup the Guest OS configures it's IP address and restarts. Our training rooms have Wyse terminals and each terminal is configured to RDP to an address which is based on the room and desk identifiers. Hence room 1 desk 1 will attempt to connect to "192.168.1.1".

Yes I know LabManager is available and we do use it, but in this case we don't have many images and they don't change frequently. Plus the I haven't found a way of communicating the public IP address if I enable ring fencing, which is NAT.

This solution means that just the Guest OS needs to reconfigure and when they're finished they shutdown.

Reply
0 Kudos
askquestion
Contributor
Contributor

How can we find the total number of CPU's/Cores assign to guest machine ? Is there any API is available to get the total number of guest machine ?

Reply
0 Kudos
aixylinux
Contributor
Contributor

I have a similar situation. I have a bunch of Windows VMs cloned from a master image, for classroom use. They get recloned after each class. They all have the same hostname and IP address. They sit behind a NAT so to the "outside" they have unique hostnames/IP addresses. And, of course, the ESX VM names are different. Is there a direct way using the Perl API (or any other) for the guest OS to inquire about itself? I will use this information to customize other aspects of the guest. I could use the guestinfo.variable technique in the VMX file, but I prefer to do something directly with the API. Just a simple "who am I" would do the trick. I've thought of sending an HTTP request to a CGI script on an outside web server, which could return the "real" IP address.

Reply
0 Kudos
Dick_Murray
Contributor
Contributor

I've got a workaround at the moment which may be of interest.

We use Wyse terminals to access our images for training, which is why I needed the IP address.

My base XP image has ipfw loaded in place of the XP firewall, which means I can control in and more importantly out traffic as well.

I only allow DHCP and RDP to flow and have each batch of images assigned to a separate subnet. Each subnet has a maximum of 30 hosts, but I only allow DHCP to give out as many hosts as there are VM's in the batch.

Then we use RDP to access them. Seems to work well and ipfw stops each VM finding out about it's neighbour.

Maybe they'll modify LabManager at some point in the future...

Also working on an API script which isn't working at the moment... Smiley Happy

Reply
0 Kudos
ullbergm
Enthusiast
Enthusiast

Basically, through VI SDK you can retrire the IP, hostname and VM name based on Guest IP or Hostname.

Thanks Boris, i've been looking for a way to do this myself and i had not thought about doing it the way you are describing.

I'll probably end up use the MAC address as the key since I don't want to have to rely on the vmware tools updating the ipaddress in Virtual Center in time as my script will run as soon as the VM starts up.

Check out my orchestration blog here: http://ullberg.us/orchestrate/
Reply
0 Kudos