Search in sources :

Example 1 with TraversalSpec

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

the class ClusterMO method getVmPropertiesOnHyperHost.

@Override
public ObjectContent[] getVmPropertiesOnHyperHost(String[] propertyPaths) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - retrieveProperties() for VM properties. target MOR: " + _mor.get_value() + ", properties: " + new Gson().toJson(propertyPaths));
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("VirtualMachine");
    pSpec.setPathSet(propertyPaths);
    TraversalSpec host2VmFolderTraversal = new TraversalSpec();
    host2VmFolderTraversal.setType("HostSystem");
    host2VmFolderTraversal.setPath("vm");
    host2VmFolderTraversal.setName("host2VmFolderTraversal");
    TraversalSpec cluster2HostFolderTraversal = new TraversalSpec();
    cluster2HostFolderTraversal.setType("ClusterComputeResource");
    cluster2HostFolderTraversal.setPath("host");
    cluster2HostFolderTraversal.setName("cluster2HostFolderTraversal");
    cluster2HostFolderTraversal.setSelectSet(new SelectionSpec[] { host2VmFolderTraversal });
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(getMor());
    oSpec.setSkip(Boolean.TRUE);
    oSpec.setSelectSet(new SelectionSpec[] { cluster2HostFolderTraversal });
    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.setPropSet(new PropertySpec[] { pSpec });
    pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
    ObjectContent[] properties = _context.getService().retrieveProperties(_context.getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - retrieveProperties() done");
    return properties;
}
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) Gson(com.google.gson.Gson)

Example 2 with TraversalSpec

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

the class ClusterMO 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.get_value() + ", properties: " + new Gson().toJson(propertyPaths));
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Datastore");
    pSpec.setPathSet(propertyPaths);
    TraversalSpec cluster2DatastoreTraversal = new TraversalSpec();
    cluster2DatastoreTraversal.setType("ClusterComputeResource");
    cluster2DatastoreTraversal.setPath("datastore");
    cluster2DatastoreTraversal.setName("cluster2DatastoreTraversal");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.setSelectSet(new SelectionSpec[] { cluster2DatastoreTraversal });
    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.setPropSet(new PropertySpec[] { pSpec });
    pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
    ObjectContent[] properties = _context.getService().retrieveProperties(_context.getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - retrieveProperties() done");
    return properties;
}
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) Gson(com.google.gson.Gson)

Example 3 with TraversalSpec

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

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.setPathSet(new String[] { "key", "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.setSelectSet(new SelectionSpec[] { datacenter2DvPortGroupTraversal });
    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[] props = oc.getPropSet();
            if (props != null) {
                assert (props.length == 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.get_value())) {
                    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) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 4 with TraversalSpec

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

the class DatacenterMO method getDvPortGroupMor.

public ManagedObjectReference getDvPortGroupMor(String dvPortGroupName) throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("DistributedVirtualPortgroup");
    pSpec.setPathSet(new String[] { "name" });
    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.setSelectSet(new SelectionSpec[] { datacenter2DvPortGroupTraversal });
    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[] props = oc.getPropSet();
            if (props != null) {
                for (DynamicProperty prop : props) {
                    if (prop.getVal().equals(dvPortGroupName))
                        return oc.getObj();
                }
            }
        }
    }
    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)

Example 5 with TraversalSpec

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

the class DatacenterMO method getDatastorePropertiesOnDatacenter.

public ObjectContent[] getDatastorePropertiesOnDatacenter(String[] propertyPaths) throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Datastore");
    pSpec.setPathSet(propertyPaths);
    TraversalSpec dc2DatastoreTraversal = new TraversalSpec();
    dc2DatastoreTraversal.setType("Datacenter");
    dc2DatastoreTraversal.setPath("datastore");
    dc2DatastoreTraversal.setName("dc2DatastoreTraversal");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.setSelectSet(new SelectionSpec[] { dc2DatastoreTraversal });
    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.setPropSet(new PropertySpec[] { pSpec });
    pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
    return _context.getService().retrieveProperties(_context.getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec)

Aggregations

TraversalSpec (com.vmware.vim25.TraversalSpec)52 ObjectSpec (com.vmware.vim25.ObjectSpec)47 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)47 PropertySpec (com.vmware.vim25.PropertySpec)47 ObjectContent (com.vmware.vim25.ObjectContent)34 ArrayList (java.util.ArrayList)30 SelectionSpec (com.vmware.vim25.SelectionSpec)16 DynamicProperty (com.vmware.vim25.DynamicProperty)14 Gson (com.google.gson.Gson)10 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 ObjectSpecBuilder (com.vmware.photon.controller.model.adapters.vsphere.util.builders.ObjectSpecBuilder)1 PropertyFilterSpecBuilder (com.vmware.photon.controller.model.adapters.vsphere.util.builders.PropertyFilterSpecBuilder)1 PropertySpecBuilder (com.vmware.photon.controller.model.adapters.vsphere.util.builders.PropertySpecBuilder)1 SelectionSpecBuilder (com.vmware.photon.controller.model.adapters.vsphere.util.builders.SelectionSpecBuilder)1 TraversalSpecBuilder (com.vmware.photon.controller.model.adapters.vsphere.util.builders.TraversalSpecBuilder)1 RetrieveOptions (com.vmware.vim25.RetrieveOptions)1