Search in sources :

Example 36 with PropertySpec

use of com.vmware.vim25.PropertySpec in project photon-model by vmware.

the class GetMoRef method entityProps.

/**
 * Method to retrieve properties of a {@link ManagedObjectReference}
 *
 * @param entityMor {@link ManagedObjectReference} of the entity
 * @param props     Array of properties to be looked up
 * @return Map of the property name and its corresponding value
 * @throws InvalidPropertyFaultMsg If a property does not exist
 * @throws RuntimeFaultFaultMsg
 */
public Map<String, Object> entityProps(ManagedObjectReference entityMor, String... props) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    init();
    final HashMap<String, Object> retVal = new HashMap<>();
    // Create PropertyFilterSpec using the PropertySpec and ObjectPec
    PropertyFilterSpec[] propertyFilterSpecs = { new PropertyFilterSpecBuilder().propSet(// Create Property Spec
    new PropertySpecBuilder().all(Boolean.FALSE).type(entityMor.getType()).pathSet(props)).objectSet(// Now create Object Spec
    new ObjectSpecBuilder().obj(entityMor)) };
    List<ObjectContent> oCont = this.vimPort.retrievePropertiesEx(this.serviceContent.getPropertyCollector(), Arrays.asList(propertyFilterSpecs), new RetrieveOptions()).getObjects();
    if (oCont != null) {
        for (ObjectContent oc : oCont) {
            List<DynamicProperty> dps = oc.getPropSet();
            for (DynamicProperty dp : dps) {
                retVal.put(dp.getName(), dp.getVal());
            }
        }
    }
    return retVal;
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) DynamicProperty(com.vmware.vim25.DynamicProperty) HashMap(java.util.HashMap) PropertyFilterSpecBuilder(com.vmware.photon.controller.model.adapters.vsphere.util.builders.PropertyFilterSpecBuilder) RetrieveOptions(com.vmware.vim25.RetrieveOptions) ObjectContent(com.vmware.vim25.ObjectContent) PropertySpecBuilder(com.vmware.photon.controller.model.adapters.vsphere.util.builders.PropertySpecBuilder) ObjectSpecBuilder(com.vmware.photon.controller.model.adapters.vsphere.util.builders.ObjectSpecBuilder)

Example 37 with PropertySpec

use of com.vmware.vim25.PropertySpec in project photon-model by vmware.

the class WaitForValues method propertyFilterSpec.

private PropertyFilterSpec propertyFilterSpec(ManagedObjectReference objmor, String[] filterProps, String[] propsToMatch) {
    PropertyFilterSpec spec = new PropertyFilterSpec();
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(objmor);
    oSpec.setSkip(Boolean.FALSE);
    spec.getObjectSet().add(oSpec);
    Set<String> uniqPropSet = new HashSet<>(Arrays.asList(filterProps));
    uniqPropSet.addAll(Arrays.asList(propsToMatch));
    PropertySpec pSpec = new PropertySpec();
    pSpec.getPathSet().addAll(new ArrayList<>(uniqPropSet));
    pSpec.setType(objmor.getType());
    spec.getPropSet().add(pSpec);
    return spec;
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) HashSet(java.util.HashSet)

Example 38 with PropertySpec

use of com.vmware.vim25.PropertySpec 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));
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec) SelectionSpec(com.vmware.vim25.SelectionSpec)

Example 39 with PropertySpec

use of com.vmware.vim25.PropertySpec 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);
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec)

Example 40 with PropertySpec

use of com.vmware.vim25.PropertySpec 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);
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec)

Aggregations

PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)61 ObjectSpec (com.vmware.vim25.ObjectSpec)60 PropertySpec (com.vmware.vim25.PropertySpec)60 TraversalSpec (com.vmware.vim25.TraversalSpec)47 ObjectContent (com.vmware.vim25.ObjectContent)41 ArrayList (java.util.ArrayList)34 DynamicProperty (com.vmware.vim25.DynamicProperty)20 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)12 SelectionSpec (com.vmware.vim25.SelectionSpec)11 Gson (com.google.gson.Gson)10 Pair (com.cloud.utils.Pair)4 HashMap (java.util.HashMap)4 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)3 RetrieveOptions (com.vmware.vim25.RetrieveOptions)3 VirtualMachineFileInfo (com.vmware.vim25.VirtualMachineFileInfo)3 ObjectSpecBuilder (com.vmware.photon.controller.model.adapters.vsphere.util.builders.ObjectSpecBuilder)2 PropertyFilterSpecBuilder (com.vmware.photon.controller.model.adapters.vsphere.util.builders.PropertyFilterSpecBuilder)2 PropertySpecBuilder (com.vmware.photon.controller.model.adapters.vsphere.util.builders.PropertySpecBuilder)2 ObjectUpdate (com.vmware.vim25.ObjectUpdate)2 PropertyChange (com.vmware.vim25.PropertyChange)2