I am trying to figure out how to get a subset of properties from a ManagedObjectReference to HostSystem.
My current use case is that I am using a property collector to retrieve all VirtualMachines. One of the properties I am retrieving is the host property for the VirtualMachine. All I want to get is the name of the host that the VirtualMachine belongs to.
If anyone knows how I can do this in Java that would be a huge help!
I was able to figure this out.
In the vSphere Web Services SDK Programming Guide - VMware vSphere 6.7 starting on page 75, there is an Example: Inventory Traversal in Java that shows how to extend the TraversalSpec to a nested managed object.
Here is a snippet of that example
// extend from virtual machine to network TraversalSpec
tSpecVmN = new TraversalSpec();
tSpecVmN.setType("VirtualMachine");
tSpecVmN.setPath("network");
tSpecVmN.setSkip(false);
// add the network traversal specs
// to the virtual machine traversal;
// the accessor method (getSelectSet) returns a reference
// to the mapped XML representation of the list; using this
// reference to add the spec will update the selectSet list
tSpec.getSelectSet().add(tSpecVmN);
I was able to figure this out.
In the vSphere Web Services SDK Programming Guide - VMware vSphere 6.7 starting on page 75, there is an Example: Inventory Traversal in Java that shows how to extend the TraversalSpec to a nested managed object.
Here is a snippet of that example
// extend from virtual machine to network TraversalSpec
tSpecVmN = new TraversalSpec();
tSpecVmN.setType("VirtualMachine");
tSpecVmN.setPath("network");
tSpecVmN.setSkip(false);
// add the network traversal specs
// to the virtual machine traversal;
// the accessor method (getSelectSet) returns a reference
// to the mapped XML representation of the list; using this
// reference to add the spec will update the selectSet list
tSpec.getSelectSet().add(tSpecVmN);