Search in sources :

Example 21 with PropertyFilterSpec

use of com.vmware.vim25.PropertyFilterSpec 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 22 with PropertyFilterSpec

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

the class HostMO method getDatastorePropertiesOnHyperHost.

@Override
public ObjectContent[] getDatastorePropertiesOnHyperHost(String[] propertyPaths) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - retrieveProperties() on Datastore properties. target MOR: " + _mor.getValue() + ", properties: " + new Gson().toJson(propertyPaths));
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Datastore");
    pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));
    TraversalSpec host2DatastoreTraversal = new TraversalSpec();
    host2DatastoreTraversal.setType("HostSystem");
    host2DatastoreTraversal.setPath("datastore");
    host2DatastoreTraversal.setName("host2DatastoreTraversal");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(host2DatastoreTraversal);
    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
    pfSpecArr.add(pfSpec);
    List<ObjectContent> properties = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - retrieveProperties() done");
    return properties.toArray(new ObjectContent[properties.size()]);
}
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) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson)

Example 23 with PropertyFilterSpec

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

the class VirtualMachineMO method getFileLayout.

public VirtualMachineFileLayoutEx getFileLayout() throws Exception {
    VirtualMachineFileLayoutEx fileLayout = null;
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("VirtualMachine");
    pSpec.getPathSet().add("layoutEx");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.FALSE);
    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) {
                for (DynamicProperty prop : props) {
                    if (prop.getName().equals("layoutEx")) {
                        fileLayout = (VirtualMachineFileLayoutEx) prop.getVal();
                        break;
                    }
                }
            }
        }
    }
    return fileLayout;
}
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) ArrayList(java.util.ArrayList) VirtualMachineFileLayoutEx(com.vmware.vim25.VirtualMachineFileLayoutEx)

Example 24 with PropertyFilterSpec

use of com.vmware.vim25.PropertyFilterSpec in project CloudStack-archive by CloudStack-extras.

the class VirtualMachineMO method getNetworks.

public String[] getNetworks() throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Network");
    pSpec.setPathSet(new String[] { "name" });
    TraversalSpec vm2NetworkTraversal = new TraversalSpec();
    vm2NetworkTraversal.setType("VirtualMachine");
    vm2NetworkTraversal.setPath("network");
    vm2NetworkTraversal.setName("vm2NetworkTraversal");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.setSelectSet(new SelectionSpec[] { vm2NetworkTraversal });
    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.setPropSet(new PropertySpec[] { pSpec });
    pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
    ObjectContent[] ocs = _context.getService().retrieveProperties(_context.getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
    List<String> networks = new ArrayList<String>();
    if (ocs != null && ocs.length > 0) {
        for (ObjectContent oc : ocs) {
            networks.add(oc.getPropSet(0).getVal().toString());
        }
    }
    return networks.toArray(new String[0]);
}
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) ArrayList(java.util.ArrayList)

Example 25 with PropertyFilterSpec

use of com.vmware.vim25.PropertyFilterSpec in project CloudStack-archive by CloudStack-extras.

the class VirtualMachineMO method getOwnerDatastore.

public Pair<DatastoreMO, String> getOwnerDatastore(String dsFullPath) throws Exception {
    String dsName = DatastoreFile.getDatastoreNameFromPath(dsFullPath);
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Datastore");
    pSpec.setPathSet(new String[] { "name" });
    TraversalSpec vmDatastoreTraversal = new TraversalSpec();
    vmDatastoreTraversal.setType("VirtualMachine");
    vmDatastoreTraversal.setPath("datastore");
    vmDatastoreTraversal.setName("vmDatastoreTraversal");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.setSelectSet(new SelectionSpec[] { vmDatastoreTraversal });
    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.setPropSet(new PropertySpec[] { pSpec });
    pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
    ObjectContent[] ocs = _context.getService().retrieveProperties(_context.getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
    if (ocs != null) {
        for (ObjectContent oc : ocs) {
            DynamicProperty prop = oc.getPropSet(0);
            if (prop.getVal().toString().equals(dsName)) {
                return new Pair<DatastoreMO, String>(new DatastoreMO(_context, oc.getObj()), dsName);
            }
        }
    }
    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) Pair(com.cloud.utils.Pair)

Aggregations

ObjectSpec (com.vmware.vim25.ObjectSpec)45 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)45 PropertySpec (com.vmware.vim25.PropertySpec)45 TraversalSpec (com.vmware.vim25.TraversalSpec)38 ObjectContent (com.vmware.vim25.ObjectContent)35 ArrayList (java.util.ArrayList)26 DynamicProperty (com.vmware.vim25.DynamicProperty)16 Gson (com.google.gson.Gson)10 SelectionSpec (com.vmware.vim25.SelectionSpec)9 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)7 Pair (com.cloud.utils.Pair)4 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)2 CustomFieldStringValue (com.vmware.vim25.CustomFieldStringValue)2 DVPortgroupConfigInfo (com.vmware.vim25.DVPortgroupConfigInfo)2 VirtualMachineFileInfo (com.vmware.vim25.VirtualMachineFileInfo)2 InvalidPropertyFaultMsg (com.vmware.vim25.InvalidPropertyFaultMsg)1 ObjectUpdate (com.vmware.vim25.ObjectUpdate)1 PropertyChange (com.vmware.vim25.PropertyChange)1 PropertyFilterUpdate (com.vmware.vim25.PropertyFilterUpdate)1 RuntimeFaultFaultMsg (com.vmware.vim25.RuntimeFaultFaultMsg)1