We have list of VMs available in a HostSystem, but is there a way to fetch the information the other way around? i.e. having a VirtualMachine ManagedEntity and fetching it's HostSystem.
Hi,
You can fetch the same using VirtualMachineRuntimeInfo property from the VM managed object as follows: VM.runtime.host
- Angela.
Thanks Angela,
The VirtualMachineRuntimeInfo gives us MOR rather than the Managed Entity, thats why we refrained from using it as we need Managed Entity of HostSystem.
Moreover, you may ask why we aren't using HostSystem's vm property to fetch the VirtualMachines and maintain a map of them by ourselves. Reason is that for that to work we will first need to fetch all the hosts and then for each host, call the vm property. That makes it two calls to our vCenter.
What we are currently using PropertyFilterSpec to fetch all Hosts and VMs at once, this gives us all the information to us except for the relation between the Hosts and VMs.
If you have the host MOR, you have everything you need.
You can compare the MOR directly with MORs from other VMs for equality, making no remote calls.
If you need to invoke a HostSystem method (which is always a remote call), the WSDL takes
the MOR as the first argument of (e.g.) DisconnectHost_Task.
If you're using a client toolkit, it will have some way to build a proxy from the MOR. In Steve's VI Java,
for example, it looks like
ManagedObjectReference hmor = vmRuntimeInfo.getHost();
HostSystem host = new HostSystem(vm.getServerConnection(), hmor);