Search in sources :

Example 16 with PropertySpec

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

the class Lister method listResourcePool.

private List<Element> listResourcePool() throws FinderException, InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ObjectSpec ospec = new ObjectSpec();
    ospec.setObj(this.start);
    ospec.setSkip(true);
    for (String f : new String[] { "resourcePool" }) {
        TraversalSpec tspec = new TraversalSpec();
        tspec.setPath(f);
        tspec.setSkip(false);
        tspec.setType("ResourcePool");
        ospec.getSelectSet().add(tspec);
    }
    List<PropertySpec> pspecs = new ArrayList<>();
    for (String t : new String[] { "ResourcePool" }) {
        PropertySpec pspec = new PropertySpec();
        pspec.setType(t);
        pspec.getPathSet().add("name");
        pspecs.add(pspec);
    }
    PropertyFilterSpec spec = new PropertyFilterSpec();
    spec.getObjectSet().add(ospec);
    spec.getPropSet().addAll(pspecs);
    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) ArrayList(java.util.ArrayList)

Example 17 with PropertySpec

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

the class EnumerationClient method createResourcesFilterSpec.

public PropertyFilterSpec createResourcesFilterSpec() {
    ObjectSpec ospec = new ObjectSpec();
    ospec.setObj(this.datacenter);
    ospec.setSkip(false);
    ospec.getSelectSet().addAll(buildFullTraversal());
    PropertySpec hostSpec = new PropertySpec();
    hostSpec.setType(VimNames.TYPE_HOST);
    hostSpec.getPathSet().addAll(Arrays.asList(VimPath.host_summary_hardware_memorySize, VimPath.host_summary_hardware_cpuMhz, VimPath.host_summary_hardware_numCpuCores, VimPath.host_summary_hardware_uuid, VimPath.host_summary_runtime_inMaintenanceMode, VimPath.host_parent, VimPath.host_datastore, VimPath.host_network, VimNames.PROPERTY_NAME, VimPath.host_summary_hardware_numNics, VimPath.host_summary_hardware_numCpuPkgs, VimPath.host_summary_hardware_vendor, VimPath.host_summary_hardware_model, VimPath.host_summary_hardware_cpuModel, VimPath.host_config_network_pnic, VimPath.host_config_hyperThread_active, VimPath.host_config_hyperThread_available));
    PropertySpec rpSpec = new PropertySpec();
    rpSpec.setType(VimNames.TYPE_RESOURCE_POOL);
    rpSpec.getPathSet().addAll(Arrays.asList(VimPath.rp_summary_config_memoryAllocation_limit, VimPath.rp_runtime_memory_reservationUsed, VimPath.rp_runtime_memory_maxUsage, VimPath.rp_runtime_cpu_reservationUsed, VimPath.rp_runtime_cpu_maxUsage, VimNames.PROPERTY_PARENT, VimNames.PROPERTY_OWNER, VimNames.PROPERTY_NAME));
    PropertySpec clusterSpec = new PropertySpec();
    clusterSpec.setType(VimNames.TYPE_COMPUTE_RESOURCE);
    clusterSpec.getPathSet().addAll(Arrays.asList(VimPath.res_summary_numCpuCores, VimPath.res_summary_totalCpu, VimPath.res_summary_totalMemory, VimPath.res_resourcePool, VimPath.res_configurationEx, VimPath.res_host, VimPath.res_datastore, VimPath.res_network, VimNames.PROPERTY_NAME));
    PropertySpec dsSpec = new PropertySpec();
    dsSpec.setType(VimNames.TYPE_DATASTORE);
    dsSpec.getPathSet().addAll(Arrays.asList(VimPath.ds_summary_type, VimPath.ds_summary_freeSpace, VimPath.ds_summary_capacity, VimPath.ds_summary_url, VimNames.PROPERTY_NAME));
    PropertySpec netSpec = new PropertySpec();
    netSpec.setType(VimNames.TYPE_NETWORK);
    netSpec.getPathSet().addAll(Arrays.asList(VimNames.PROPERTY_NAME, VimPath.net_summary));
    PropertySpec pgSpec = new PropertySpec();
    pgSpec.setType(VimNames.TYPE_PORTGROUP);
    pgSpec.getPathSet().addAll(Arrays.asList(VimPath.pg_config_distributedVirtualSwitch, VimPath.pg_config_key, VimNames.PROPERTY_NAME));
    PropertySpec dvsSpec = new PropertySpec();
    dvsSpec.setType(VimNames.TYPE_DVS);
    dvsSpec.getPathSet().addAll(Arrays.asList(VimNames.PROPERTY_NAME, VimPath.dvs_uuid));
    PropertySpec folderSpec = new PropertySpec();
    folderSpec.setType(VimNames.TYPE_FOLDER);
    // TODO: Select only required properties
    folderSpec.setAll(true);
    PropertyFilterSpec filterSpec = new PropertyFilterSpec();
    filterSpec.getObjectSet().add(ospec);
    filterSpec.getPropSet().add(hostSpec);
    filterSpec.getPropSet().add(rpSpec);
    filterSpec.getPropSet().add(clusterSpec);
    filterSpec.getPropSet().add(dsSpec);
    filterSpec.getPropSet().add(netSpec);
    filterSpec.getPropSet().add(pgSpec);
    filterSpec.getPropSet().add(dvsSpec);
    filterSpec.getPropSet().add(folderSpec);
    return filterSpec;
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec)

Example 18 with PropertySpec

use of com.vmware.vim25.PropertySpec in project cloudstack by apache.

the class VMwareUtil method getEntityProps.

public static Map<String, Object> getEntityProps(VMwareConnection connection, ManagedObjectReference entityMor, String[] props) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    Map<String, Object> retVal = new HashMap<>();
    PropertySpec propertySpec = new PropertySpec();
    propertySpec.setAll(Boolean.FALSE);
    propertySpec.setType(entityMor.getType());
    propertySpec.getPathSet().addAll(Arrays.asList(props));
    ObjectSpec objectSpec = new ObjectSpec();
    objectSpec.setObj(entityMor);
    // Create PropertyFilterSpec using the PropertySpec and ObjectPec created above.
    PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpec();
    propertyFilterSpec.getPropSet().add(propertySpec);
    propertyFilterSpec.getObjectSet().add(objectSpec);
    List<PropertyFilterSpec> propertyFilterSpecs = new ArrayList<>();
    propertyFilterSpecs.add(propertyFilterSpec);
    RetrieveResult rslts = connection.getVimPortType().retrievePropertiesEx(connection.getServiceContent().getPropertyCollector(), propertyFilterSpecs, new RetrieveOptions());
    List<ObjectContent> listobjcontent = new ArrayList<>();
    if (rslts != null && rslts.getObjects() != null && !rslts.getObjects().isEmpty()) {
        listobjcontent.addAll(rslts.getObjects());
    }
    String token = null;
    if (rslts != null && rslts.getToken() != null) {
        token = rslts.getToken();
    }
    while (token != null && !token.isEmpty()) {
        rslts = connection.getVimPortType().continueRetrievePropertiesEx(connection.getServiceContent().getPropertyCollector(), token);
        token = null;
        if (rslts != null) {
            token = rslts.getToken();
            if (rslts.getObjects() != null && !rslts.getObjects().isEmpty()) {
                listobjcontent.addAll(rslts.getObjects());
            }
        }
    }
    for (ObjectContent oc : listobjcontent) {
        List<DynamicProperty> dps = oc.getPropSet();
        if (dps != null) {
            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) ArrayList(java.util.ArrayList) RetrieveOptions(com.vmware.vim25.RetrieveOptions) ObjectContent(com.vmware.vim25.ObjectContent) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) RetrieveResult(com.vmware.vim25.RetrieveResult)

Example 19 with PropertySpec

use of com.vmware.vim25.PropertySpec in project cloudstack by apache.

the class DatacenterMO method getDvSwitchMor.

public ManagedObjectReference getDvSwitchMor(ManagedObjectReference dvPortGroupMor) throws Exception {
    String dvPortGroupKey = null;
    ManagedObjectReference dvSwitchMor = null;
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("DistributedVirtualPortgroup");
    pSpec.getPathSet().add("key");
    pSpec.getPathSet().add("config.distributedVirtualSwitch");
    TraversalSpec datacenter2DvPortGroupTraversal = new TraversalSpec();
    datacenter2DvPortGroupTraversal.setType("Datacenter");
    datacenter2DvPortGroupTraversal.setPath("network");
    datacenter2DvPortGroupTraversal.setName("datacenter2DvPortgroupTraversal");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(datacenter2DvPortGroupTraversal);
    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
    pfSpecArr.add(pfSpec);
    List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
    if (ocs != null) {
        for (ObjectContent oc : ocs) {
            List<DynamicProperty> props = oc.getPropSet();
            if (props != null) {
                assert (props.size() == 2);
                for (DynamicProperty prop : props) {
                    if (prop.getName().equals("key")) {
                        dvPortGroupKey = (String) prop.getVal();
                    } else {
                        dvSwitchMor = (ManagedObjectReference) prop.getVal();
                    }
                }
                if ((dvPortGroupKey != null) && dvPortGroupKey.equals(dvPortGroupMor.getValue())) {
                    return dvSwitchMor;
                }
            }
        }
    }
    return null;
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectContent(com.vmware.vim25.ObjectContent) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) DynamicProperty(com.vmware.vim25.DynamicProperty) TraversalSpec(com.vmware.vim25.TraversalSpec) ArrayList(java.util.ArrayList) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 20 with PropertySpec

use of com.vmware.vim25.PropertySpec in project cloudstack by apache.

the class DatastoreMO method getOwnerDatacenter.

public Pair<DatacenterMO, String> getOwnerDatacenter() throws Exception {
    if (_ownerDc != null)
        return _ownerDc;
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Datacenter");
    pSpec.getPathSet().add("name");
    TraversalSpec folderParentTraversal = new TraversalSpec();
    folderParentTraversal.setType("Folder");
    folderParentTraversal.setPath("parent");
    folderParentTraversal.setName("folderParentTraversal");
    SelectionSpec sSpec = new SelectionSpec();
    sSpec.setName("folderParentTraversal");
    folderParentTraversal.getSelectSet().add(sSpec);
    TraversalSpec dsParentTraversal = new TraversalSpec();
    dsParentTraversal.setType("Datastore");
    dsParentTraversal.setPath("parent");
    dsParentTraversal.setName("dsParentTraversal");
    dsParentTraversal.getSelectSet().add(folderParentTraversal);
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(getMor());
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(dsParentTraversal);
    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> pfSpecArr = new ArrayList<>();
    pfSpecArr.add(pfSpec);
    List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
    assert (ocs != null && ocs.size() > 0);
    assert (ocs.get(0).getObj() != null);
    assert (ocs.get(0).getPropSet() != null);
    String dcName = ocs.get(0).getPropSet().get(0).getVal().toString();
    _ownerDc = new Pair<>(new DatacenterMO(_context, ocs.get(0).getObj()), dcName);
    return _ownerDc;
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectContent(com.vmware.vim25.ObjectContent) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec) SelectionSpec(com.vmware.vim25.SelectionSpec) ArrayList(java.util.ArrayList)

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