I'm trying to get the host details related to a VM, so that I can construct a link to the Web console. Code:
if (dp.getName().equals("runtime")) {
VirtualMachineRuntimeInfo runtimeInfo = (VirtualMachineRuntimeInfo) dp.getVal();
ManagedObjectReference hostInfo = runtimeInfo.getHost();
getInfoHote(hostInfo);
public String getInfoHote(ManagedObjectReference hostInfo) {
ManagedObjectReference propColl = serviceContent.getPropertyCollector();
try {
List<String> vmList = new ArrayList<String>();
vmList.add("HostSystem");
ManagedObjectReference cViewRef = vimPort.createContainerView(hostInfo,
serviceContent.getRootFolder(),
vmList,
true);
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(cViewRef);
oSpec.setSkip(true);
TraversalSpec tSpec = new TraversalSpec();
tSpec.setName("traverseEntities");
tSpec.setPath("view");
tSpec.setSkip(false);
tSpec.setType("ContainerView");
oSpec.getSelectSet().add(tSpec);
PropertySpec pSpec = new PropertySpec();
pSpec.setType("HostSystem");
pSpec.getPathSet().add("config");
PropertyFilterSpec fSpec = new PropertyFilterSpec();
fSpec.getObjectSet().add(oSpec);
fSpec.getPropSet().add(pSpec);
List<PropertyFilterSpec> fSpecList = new ArrayList<PropertyFilterSpec>();
fSpecList.add(fSpec);
RetrieveOptions ro = new RetrieveOptions();
RetrieveResult props = vimPort.retrievePropertiesEx(propColl,fSpecList,ro);