VMware {code} Community
eatorres
Enthusiast
Enthusiast

Using Vix to list all VMs in an ESX Virtual Network

I am trying to write a program using Vix 1.6.2 to automate some testing using VMs on ESX 3.5. I am familiar with using the Vix API with Workstation 6.5. I would like to know if there is any way to get a list of the VMs on an ESX server? It would help if I could get a list of machines in each of the Virtual Networks I have set up, but just a general list of all machines that ESX is managing would be good too. What I'm trying to do is set up a loop that will loop through all the VMs and run a program on each one. Thanks!

0 Kudos
3 Replies
admin
Immortal
Immortal

You can get the VMs using VIX, for example you can use vmrun's list command.

There are some problems doing what you're hoping to do though. For one, VIX will only return the list of powered on VMs. If you need to map VMs to virtual networks you can't do that with VIX, for this you'll need to use the VI API. So for anything beyond the relatively basic "list all VM names and run something inside them" you'll need a combination of VI API and VIX.

eatorres
Enthusiast
Enthusiast

Thanks, I ended up using a combination of VI API and Vix to get the list of VMs.

0 Kudos
zcoolmatz
Contributor
Contributor

I developped some code in CSharp and it look like this:

...

VixCOM.IVixLib vixLib = null;

ulong m_vixError;

VixCOM.IHost m_hostHandle = null;

VixCOM.IVM m_vmHandle = null;

...

public void RefreshLists()

{

lstVmServers.Clear();
DiscoveryCallback callback = new DiscoveryCallback(vixLib);
IJob jobHandle = m_hostHandle.FindItems(VixCOM.Constants.VIX_FIND_REGISTERED_VMS, null, -1, callback);
m_vixError = jobHandle.WaitWithoutResults();
if (m_vixError == VixCOM.Constants.VIX_OK)
{
lstVmServers.AddRange(callback.GetListOfStorage());
}

}

You must be connected first (check the VixWrapper).

I suggest you to not use the VM API anymore, it will be deprecated soon (I think).

Have fun!

0 Kudos