VMware {code} Community
cvstealth
Contributor
Contributor

VIX API VM IP Address Info

Currently I'm using the VIX Perl 1.6.2 API to communicate to a Server 2.0 install. I have used the API to successfully register/poweron/suspend/shutdown a particular VM. I was wondering if there was a way to use the API to extract the IP information for a given VM. I looked into using the functions GetProperties and FindItems but I couldn't find the appropriate constraint in vix.h that would correspond with the IP info. I know that the VMWare guest tools are presenting that information to the host because you can see it in the web management interface. Any help in regards to extracting this information from the API would be greatly appreciated.

Regards, Matt

0 Kudos
3 Replies
dblock
Enthusiast
Enthusiast

It's a guest variable (VIX_VM_GUEST_VARIABLE) called "ip". You need to call GetVariable(VIX_VM_GUEST_VARIABLE, "ip", ...)

Look at this C# source. virtualMachine.GuestVariables gives you the ip.

0 Kudos
cvstealth
Contributor
Contributor

dblock: Thank you for the answer that works perfectly. For those that need it this was the block of code to use:

  1. grab ip information from vmware tools

($err, $ip) = VMReadVariable($vmHandle, VIX_VM_GUEST_VARIABLE, "ip", 0); # options

if ($err != VIX_OK)

{

print "VMReadVariable() failed, $err ". GetErrorText($err));

}

0 Kudos
cvstealth
Contributor
Contributor

I did have 1 more question: I need to get the vmid/guestId for a particular VM, does anyone know what the variable name is for this information?

Maybe on a related note is there anyway to call VMReadVariable and get back an enumeration/array/hash table of all fields and their values?

root@demo ~# vmware-vim-cmd vmsvc/getallvms

Vmid Name File Guest OS Version Annotation

1408 windows2003-2-40 standard active/windows2003-2-40/windows2003-2-40.vmx winNetEnterpriseGuest vmx-07

^--- this column

0 Kudos