Search in sources :

Example 11 with PropertyFilterSpec

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

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.setPathSet(new String[] { "name" });
    TraversalSpec entityParentTraversal = new TraversalSpec();
    entityParentTraversal.setType("ManagedEntity");
    entityParentTraversal.setPath("parent");
    entityParentTraversal.setName("entityParentTraversal");
    entityParentTraversal.setSelectSet(new SelectionSpec[] { new SelectionSpec(null, null, "entityParentTraversal") });
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(morEntity);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.setSelectSet(new SelectionSpec[] { entityParentTraversal });
    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 });
    assert (ocs != null);
    assert (ocs[0].getObj() != null);
    assert (ocs[0].getPropSet(0) != null);
    assert (ocs[0].getPropSet(0).getVal() != null);
    String dcName = ocs[0].getPropSet(0).getVal().toString();
    return new Pair<DatacenterMO, String>(new DatacenterMO(context, ocs[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) Pair(com.cloud.utils.Pair)

Example 12 with PropertyFilterSpec

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

the class DatacenterMO method getVmPropertiesOnDatacenterVmFolder.

public ObjectContent[] getVmPropertiesOnDatacenterVmFolder(String[] propertyPaths) throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("VirtualMachine");
    pSpec.setPathSet(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.setSelectSet(new SelectionSpec[] { recurseFolders });
    dc2VmFolderTraversal.setSelectSet(new SelectionSpec[] { folder2childEntity });
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.setSelectSet(new SelectionSpec[] { dc2VmFolderTraversal });
    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) SelectionSpec(com.vmware.vim25.SelectionSpec)

Example 13 with PropertyFilterSpec

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

the class HostMO method getNetworkMor.

public ManagedObjectReference getNetworkMor(String portGroupName) throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Network");
    pSpec.setPathSet(new String[] { "summary.name" });
    TraversalSpec host2NetworkTraversal = new TraversalSpec();
    host2NetworkTraversal.setType("HostSystem");
    host2NetworkTraversal.setPath("network");
    host2NetworkTraversal.setName("host2NetworkTraversal");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.setSelectSet(new SelectionSpec[] { host2NetworkTraversal });
    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(portGroupName))
                        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 14 with PropertyFilterSpec

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

the class HostMO method getVmPropertiesOnHyperHost.

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 host2VmTraversal = new TraversalSpec();
    host2VmTraversal.setType("HostSystem");
    host2VmTraversal.setPath("vm");
    host2VmTraversal.setName("host2VmTraversal");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.setSelectSet(new SelectionSpec[] { host2VmTraversal });
    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 15 with PropertyFilterSpec

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

the class VmwareClient method getDecendentMoRef.

/**
     * Get the ManagedObjectReference for an item under the
     * specified root folder that has the type and name specified.
     *
     * @param root a root folder if available, or null for default
     * @param type type of the managed object
     * @param name name to match
     *
     * @return First ManagedObjectReference of the type / name pair found
     */
public ManagedObjectReference getDecendentMoRef(ManagedObjectReference root, String type, String name) throws Exception {
    if (name == null || name.length() == 0) {
        return null;
    }
    try {
        // Create PropertySpecs
        PropertySpec pSpec = new PropertySpec();
        pSpec.setType(type);
        pSpec.setAll(false);
        pSpec.getPathSet().add("name");
        ObjectSpec oSpec = new ObjectSpec();
        oSpec.setObj(root);
        oSpec.setSkip(false);
        oSpec.getSelectSet().addAll(constructCompleteTraversalSpec());
        PropertyFilterSpec spec = new PropertyFilterSpec();
        spec.getPropSet().add(pSpec);
        spec.getObjectSet().add(oSpec);
        List<PropertyFilterSpec> specArr = new ArrayList<PropertyFilterSpec>();
        specArr.add(spec);
        ManagedObjectReference propCollector = getPropCol();
        List<ObjectContent> ocary = vimPort.retrieveProperties(propCollector, specArr);
        if (ocary == null || ocary.size() == 0) {
            return null;
        }
        // filter through retrieved objects to get the first match.
        for (ObjectContent oc : ocary) {
            ManagedObjectReference mor = oc.getObj();
            List<DynamicProperty> propary = oc.getPropSet();
            if (type == null || type.equals(mor.getType())) {
                if (propary.size() > 0) {
                    String propval = (String) propary.get(0).getVal();
                    if (propval != null && name.equalsIgnoreCase(propval))
                        return mor;
                }
            }
        }
    } catch (InvalidPropertyFaultMsg invalidPropertyException) {
        s_logger.debug("Failed to get Vmware ManagedObjectReference for name: " + name + " and type: " + type + " due to " + invalidPropertyException.getMessage());
        throw invalidPropertyException;
    } catch (RuntimeFaultFaultMsg runtimeFaultException) {
        s_logger.debug("Failed to get Vmware ManagedObjectReference for name: " + name + " and type: " + type + " due to " + runtimeFaultException.getMessage());
        throw runtimeFaultException;
    }
    return null;
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) DynamicProperty(com.vmware.vim25.DynamicProperty) ArrayList(java.util.ArrayList) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) ObjectContent(com.vmware.vim25.ObjectContent) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

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