Search in sources :

Example 51 with PropertySpec

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

the class DatacenterMO method getVmPropertiesOnDatacenterVmFolder.

public List<ObjectContent> getVmPropertiesOnDatacenterVmFolder(String[] propertyPaths) throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("VirtualMachine");
    pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));
    TraversalSpec dc2VmFolderTraversal = new TraversalSpec();
    dc2VmFolderTraversal.setType("Datacenter");
    dc2VmFolderTraversal.setPath("vmFolder");
    dc2VmFolderTraversal.setName("dc2VmFolderTraversal");
    SelectionSpec recurseFolders = new SelectionSpec();
    recurseFolders.setName("folder2childEntity");
    TraversalSpec folder2childEntity = new TraversalSpec();
    folder2childEntity.setType("Folder");
    folder2childEntity.setPath("childEntity");
    folder2childEntity.setName(recurseFolders.getName());
    folder2childEntity.getSelectSet().add(recurseFolders);
    dc2VmFolderTraversal.getSelectSet().add(folder2childEntity);
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(dc2VmFolderTraversal);
    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) SelectionSpec(com.vmware.vim25.SelectionSpec) ArrayList(java.util.ArrayList)

Example 52 with PropertySpec

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

the class DatacenterMO method getOwnerDatacenter.

public static Pair<DatacenterMO, String> getOwnerDatacenter(VmwareContext context, ManagedObjectReference morEntity) throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Datacenter");
    pSpec.getPathSet().add("name");
    TraversalSpec entityParentTraversal = new TraversalSpec();
    entityParentTraversal.setType("ManagedEntity");
    entityParentTraversal.setPath("parent");
    entityParentTraversal.setName("entityParentTraversal");
    SelectionSpec selSpec = new SelectionSpec();
    selSpec.setName("entityParentTraversal");
    entityParentTraversal.getSelectSet().add(selSpec);
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(morEntity);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(entityParentTraversal);
    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().get(0) != null);
    assert (ocs.get(0).getPropSet().get(0).getVal() != null);
    String dcName = ocs.get(0).getPropSet().get(0).getVal().toString();
    return new Pair<DatacenterMO, String>(new DatacenterMO(context, ocs.get(0).getObj()), dcName);
}
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) Pair(com.cloud.utils.Pair)

Example 53 with PropertySpec

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

the class DatacenterMO method getHostPropertiesOnDatacenterHostFolder.

public List<ObjectContent> getHostPropertiesOnDatacenterHostFolder(String[] propertyPaths) throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("HostSystem");
    pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));
    TraversalSpec computeResource2HostTraversal = new TraversalSpec();
    computeResource2HostTraversal.setType("ComputeResource");
    computeResource2HostTraversal.setPath("host");
    computeResource2HostTraversal.setName("computeResource2HostTraversal");
    SelectionSpec recurseFolders = new SelectionSpec();
    recurseFolders.setName("folder2childEntity");
    TraversalSpec folder2childEntity = new TraversalSpec();
    folder2childEntity.setType("Folder");
    folder2childEntity.setPath("childEntity");
    folder2childEntity.setName(recurseFolders.getName());
    folder2childEntity.getSelectSet().add(recurseFolders);
    folder2childEntity.getSelectSet().add(computeResource2HostTraversal);
    TraversalSpec dc2HostFolderTraversal = new TraversalSpec();
    dc2HostFolderTraversal.setType("Datacenter");
    dc2HostFolderTraversal.setPath("hostFolder");
    dc2HostFolderTraversal.setName("dc2HostFolderTraversal");
    dc2HostFolderTraversal.getSelectSet().add(folder2childEntity);
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(dc2HostFolderTraversal);
    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) SelectionSpec(com.vmware.vim25.SelectionSpec) ArrayList(java.util.ArrayList)

Example 54 with PropertySpec

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

the class DatacenterMO method getDvPortGroupMor.

public ManagedObjectReference getDvPortGroupMor(String dvPortGroupName) throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("DistributedVirtualPortgroup");
    pSpec.getPathSet().add("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.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) {
                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) ArrayList(java.util.ArrayList)

Example 55 with PropertySpec

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

the class DatacenterMO method getDvPortGroupSpec.

public DVPortgroupConfigInfo getDvPortGroupSpec(String dvPortGroupName) throws Exception {
    DVPortgroupConfigInfo configSpec = null;
    String nameProperty = null;
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("DistributedVirtualPortgroup");
    pSpec.getPathSet().add("name");
    pSpec.getPathSet().add("config");
    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("config")) {
                        configSpec = (DVPortgroupConfigInfo) prop.getVal();
                    } else {
                        nameProperty = prop.getVal().toString();
                    }
                }
                if (nameProperty.equalsIgnoreCase(dvPortGroupName)) {
                    return configSpec;
                }
            }
        }
    }
    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) DVPortgroupConfigInfo(com.vmware.vim25.DVPortgroupConfigInfo)

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