Search in sources :

Example 6 with RetrieveOptions

use of com.vmware.vim25.RetrieveOptions 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)

Aggregations

DynamicProperty (com.vmware.vim25.DynamicProperty)4 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)4 ObjectContent (com.vmware.vim25.ObjectContent)4 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)4 RetrieveResult (com.vmware.vim25.RetrieveResult)4 HashMap (java.util.HashMap)4 ObjectSpecBuilder (com.vmware.photon.controller.model.adapters.vsphere.util.builders.ObjectSpecBuilder)3 PropertyFilterSpecBuilder (com.vmware.photon.controller.model.adapters.vsphere.util.builders.PropertyFilterSpecBuilder)3 PropertySpecBuilder (com.vmware.photon.controller.model.adapters.vsphere.util.builders.PropertySpecBuilder)3 RetrieveOptions (com.vmware.vim25.RetrieveOptions)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ObjectSpec (com.vmware.vim25.ObjectSpec)1 PropertySpec (com.vmware.vim25.PropertySpec)1 TraversalSpec (com.vmware.vim25.TraversalSpec)1