Search in sources :

Example 26 with ObjectContent

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

the class ClusterMO method getClusterHosts.

public List<Pair<ManagedObjectReference, String>> getClusterHosts() throws Exception {
    List<Pair<ManagedObjectReference, String>> hosts = new ArrayList<Pair<ManagedObjectReference, String>>();
    ObjectContent[] ocs = getHostPropertiesOnCluster(new String[] { "name" });
    if (ocs != null) {
        for (ObjectContent oc : ocs) {
            ManagedObjectReference morHost = oc.getObj();
            String name = (String) oc.getPropSet().get(0).getVal();
            hosts.add(new Pair<ManagedObjectReference, String>(morHost, name));
        }
    }
    return hosts;
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) ArrayList(java.util.ArrayList) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Pair(com.cloud.utils.Pair)

Example 27 with ObjectContent

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

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.getValue() + ", properties: " + new Gson().toJson(propertyPaths));
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Datastore");
    pSpec.getPathSet().addAll(Arrays.asList(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.getSelectSet().add(cluster2DatastoreTraversal);
    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 28 with ObjectContent

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

the class HostDatastoreSystemMO method getDatastorePropertiesOnHostDatastoreSystem.

public List<ObjectContent> getDatastorePropertiesOnHostDatastoreSystem(String[] propertyPaths) throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Datastore");
    pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));
    TraversalSpec hostDsSys2DatastoreTraversal = new TraversalSpec();
    hostDsSys2DatastoreTraversal.setType("HostDatastoreSystem");
    hostDsSys2DatastoreTraversal.setPath("datastore");
    hostDsSys2DatastoreTraversal.setName("hostDsSys2DatastoreTraversal");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(hostDsSys2DatastoreTraversal);
    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
    pfSpecArr.add(pfSpec);
    return _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
}
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 29 with ObjectContent

use of com.vmware.vim25.ObjectContent 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<PropertyFilterSpec>();
    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<DatacenterMO, String>(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)

Example 30 with ObjectContent

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

Aggregations

ObjectContent (com.vmware.vim25.ObjectContent)65 ObjectSpec (com.vmware.vim25.ObjectSpec)44 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)44 PropertySpec (com.vmware.vim25.PropertySpec)44 TraversalSpec (com.vmware.vim25.TraversalSpec)38 ArrayList (java.util.ArrayList)38 DynamicProperty (com.vmware.vim25.DynamicProperty)34 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)15 Pair (com.cloud.utils.Pair)12 Gson (com.google.gson.Gson)10 CustomFieldStringValue (com.vmware.vim25.CustomFieldStringValue)9 SelectionSpec (com.vmware.vim25.SelectionSpec)9 HashMap (java.util.HashMap)7 HostMO (com.cloud.hypervisor.vmware.mo.HostMO)5 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)4 OptionValue (com.vmware.vim25.OptionValue)4 VmwareManager (com.cloud.hypervisor.vmware.manager.VmwareManager)2 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)2 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)2 DVPortgroupConfigInfo (com.vmware.vim25.DVPortgroupConfigInfo)2