VMware {code} Community
devta
Contributor
Contributor

Getting rootfolder for the host using vmware API when host is managed by v-center.

I want to get root folder for the host when the host is managed by vcenter , as the connection is via v-center , vimapi.servicecontent object's rootfolder property is returning  v-center's rootfolder and not the hosts rootfolder hence when iterating recursively  through rootfolder it is returning all VM's for all the host managed by v-center but i need to get the rootfolder of perticular host and i have the hostref for the host (vimserv.FindbyIP(searchindex, null,ip, bVM)) ,  and i want to list only VM's for the perticular host. i am using c# language for coding.

0 Kudos
1 Reply
Steve_Jin
Expert
Expert

Hi Devta,

To list all the VMs on the host you are interested in, you don't have to get the rootFolder of the host. Once have the HostSystem object, you can get its vm property for all the virtual machines running on the host. If you use open source vijava api (http://vijava.sf.net), you just one line:

VirtualMachine[] vms = host.getVms();

Good luck!

Steve Jin, author of VMware VI and vSphere SDK, http://www.doublecloud.org

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