VMware {code} Community
samm1
Contributor
Contributor

How to get all ESX hosts from a vcenter

Hi, how do you get all esx hosts from a vcenter? I can navigate via MOB (/mob/?moid=HostProfileManager) which lists my clusters and I can then click through on those to see the hosts but I cant work out how to use the api to do this?

I dont need code examples just a top level of what method needs to be called will suffice!

Thanks

0 Kudos
3 Replies
laurentsd
VMware Employee
VMware Employee

You need to use the vSphere Web Services SDK to navigate through the vSphere objects hierarchy.  Or you can use the simpler but unsupported ViJava API from Steve Jin.

0 Kudos
Steve_Jin
Expert
Expert

As Laurent pointed out, open source vijava can help that with one line like the following:

  ManagedEntity[] mes = new InventoryNavigator(rootFolder).searchManagedEntities("HostSystem");

Check out more with the Hello World sample:

http://sourceforge.net/p/vijava/code/HEAD/tree/trunk/src/com/vmware/vim25/mo/samples/HelloVM.java

For the support, you can try the commercial version vijavaNG:

http://www.doublecloud.org/2014/01/announcing-vijavang-much-lighter-and-faster-with-commercial-licen...

Good luck!

Steve

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
0 Kudos
samm1
Contributor
Contributor



Thanks for the answers, I'm using the WSDL API. Can I access the hosts using the SearchIndex managed object or do I have to use the HostSystem managed object? When I use searchIndex with FindByPath at the top level datacenter it only shows vms, templates etc never hosts

0 Kudos