use of com.vmware.vim25.TraversalSpec in project photon-model by vmware.
the class GetMoRef method vmByVMname.
/**
* Get the MOR of the Virtual Machine by its name.
*
* @param vmName The name of the Virtual Machine
* @param propCollectorRef
* @return The Managed Object reference for this VM
* @throws RuntimeFaultFaultMsg
* @throws InvalidPropertyFaultMsg
*/
public ManagedObjectReference vmByVMname(final String vmName, final ManagedObjectReference propCollectorRef) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
init();
ManagedObjectReference rootFolder = this.serviceContent.getRootFolder();
TraversalSpec tSpec = getVMTraversalSpec();
// Create Property Spec
PropertySpec propertySpec = new PropertySpecBuilder().all(Boolean.FALSE).pathSet("name").type("VirtualMachine");
// Now create Object Spec
ObjectSpec objectSpec = new ObjectSpecBuilder().obj(rootFolder).skip(Boolean.TRUE).selectSet(tSpec);
// Create PropertyFilterSpec using the PropertySpec and ObjectPec
// created above.
PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpecBuilder().propSet(propertySpec).objectSet(objectSpec);
List<PropertyFilterSpec> listpfs = new ArrayList<PropertyFilterSpec>(1);
listpfs.add(propertyFilterSpec);
RetrieveOptions options = new RetrieveOptions();
// Query returns a fixed number of results
// if token is returned we can get more results
RetrieveResult retrieveResult = this.vimPort.retrievePropertiesEx(propCollectorRef, listpfs, options);
String token = null;
do {
token = (retrieveResult != null) ? retrieveResult.getToken() : null;
List<ObjectContent> listobcont = (retrieveResult != null) ? retrieveResult.getObjects() : null;
if (listobcont != null) {
for (ObjectContent oc : listobcont) {
ManagedObjectReference mr = oc.getObj();
String vmnm = null;
List<DynamicProperty> dps = oc.getPropSet();
if (dps != null) {
for (DynamicProperty dp : dps) {
vmnm = (String) dp.getVal();
if (vmName.equals(vmnm)) {
return mr;
}
}
}
}
}
if (token != null) {
retrieveResult = this.vimPort.continueRetrievePropertiesEx(propCollectorRef, token);
}
} while (token != null);
return null;
}
use of com.vmware.vim25.TraversalSpec in project photon-model by vmware.
the class GetMoRef method getVMTraversalSpec.
/**
* @return TraversalSpec specification to get to the VirtualMachine managed
* object.
*/
public TraversalSpec getVMTraversalSpec() {
// Create a traversal spec that starts from the 'root' objects
// and traverses the inventory tree to get to the VirtualMachines.
// Build the traversal specs bottoms up
// Traversal to get to the VM in a VApp
TraversalSpec vAppToVM = new TraversalSpecBuilder().name("vAppToVM").type("VirtualApp").path("vm");
// Traversal spec for VApp to VApp
TraversalSpec vAppToVApp = new TraversalSpecBuilder().name("vAppToVApp").type("VirtualApp").path("resourcePool").selectSet(// SelectionSpec for both VApp to VApp and VApp to VM
new SelectionSpecBuilder().name("vAppToVApp"), new SelectionSpecBuilder().name("vAppToVM"));
// This SelectionSpec is used for recursion for Folder recursion
SelectionSpec visitFolders = new SelectionSpecBuilder().name("VisitFolders");
// Traversal to get to the vmFolder from DataCenter
TraversalSpec dataCenterToVMFolder = new TraversalSpecBuilder().name("DataCenterToVMFolder").type("Datacenter").path("vmFolder").skip(false).selectSet(visitFolders);
// TraversalSpec to get to the DataCenter from rootFolder
return new TraversalSpecBuilder().name("VisitFolders").type("Folder").path("childEntity").skip(false).selectSet(visitFolders, dataCenterToVMFolder, vAppToVM, vAppToVApp);
}
use of com.vmware.vim25.TraversalSpec in project photon-model by vmware.
the class Finder method ancestrySet.
private List<ObjectContent> ancestrySet(ManagedObjectReference ref) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
ObjectSpec ospec = new ObjectSpec();
ospec.setObj(ref);
ospec.setSkip(false);
TraversalSpec tspec = new TraversalSpec();
tspec.setSkip(false);
tspec.setPath("parent");
tspec.setType("ManagedEntity");
tspec.setName("traverseParent");
SelectionSpec selSpec = new SelectionSpec();
selSpec.setName("traverseParent");
tspec.getSelectSet().add(selSpec);
ospec.getSelectSet().add(tspec);
PropertySpec pspec = new PropertySpec();
pspec.setType("ManagedEntity");
pspec.getPathSet().add("name");
pspec.getPathSet().add("parent");
PropertyFilterSpec filter = new PropertyFilterSpec();
filter.getObjectSet().add(ospec);
filter.getPropSet().add(pspec);
return this.connection.getVimPort().retrieveProperties(this.connection.getServiceContent().getPropertyCollector(), Collections.singletonList(filter));
}
use of com.vmware.vim25.TraversalSpec in project photon-model by vmware.
the class Lister method listFolder.
private List<Element> listFolder() throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, FinderException {
PropertyFilterSpec spec = new PropertyFilterSpec();
ObjectSpec objSpec = new ObjectSpec();
objSpec.setObj(this.start);
TraversalSpec selectionSpec = new TraversalSpec();
selectionSpec.setPath("childEntity");
selectionSpec.setType("Folder");
selectionSpec.setSkip(false);
objSpec.getSelectSet().add(selectionSpec);
spec.getObjectSet().add(objSpec);
// Retrieve all objects that we can deal with
String[] childTypes = { "Folder", "Datacenter", "VirtualMachine", "Network", "ComputeResource", "ClusterComputeResource", "Datastore" };
for (String t : childTypes) {
PropertySpec pspec = new PropertySpec();
pspec.setType(t);
pspec.getPathSet().add("name");
// Additional basic properties.
if (t.equals("ComputeResource") || t.equals("ClusterComputeResource")) {
// The ComputeResource and ClusterComputeResource are dereferenced in
// the ResourcePoolFlag. Make sure they always have their resourcePool
// field populated.
pspec.getPathSet().add("resourcePool");
}
spec.getPropSet().add(pspec);
}
return callPropertyCollectorAndConvert(spec);
}
use of com.vmware.vim25.TraversalSpec in project photon-model by vmware.
the class Lister method listComputeResource.
private List<Element> listComputeResource() throws FinderException, InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
ObjectSpec ospec = new ObjectSpec();
ospec.setSkip(true);
ospec.setObj(this.start);
for (String f : new String[] { "host", "resourcePool" }) {
TraversalSpec tspec = new TraversalSpec();
tspec.setPath(f);
tspec.setType("ComputeResource");
tspec.setSkip(false);
ospec.getSelectSet().add(tspec);
}
PropertyFilterSpec filter = new PropertyFilterSpec();
filter.getObjectSet().add(ospec);
for (String t : new String[] { "HostSystem", "ResourcePool" }) {
PropertySpec pspec = new PropertySpec();
pspec.setType(t);
pspec.getPathSet().add("name");
filter.getPropSet().add(pspec);
}
return callPropertyCollectorAndConvert(filter);
}
Aggregations