Search in sources :

Example 26 with ObjectSpec

use of com.vmware.vim25.ObjectSpec 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 27 with ObjectSpec

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

the class VmwareClient method validate.

public boolean validate() {
    // 
    // There is no official API to validate an open vCenter API session. This is hacking way to tell if
    // an open vCenter API session is still valid for making calls.
    // 
    // It will give false result if there really does not exist data-center in the inventory, however, I consider
    // this really is not possible in production deployment
    // 
    // Create PropertySpecs
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Datacenter");
    pSpec.setAll(false);
    pSpec.getPathSet().add("name");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(getRootFolder());
    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);
    try {
        List<ObjectContent> ocary = vimPort.retrieveProperties(getPropCol(), specArr);
        if (ocary != null && ocary.size() > 0)
            return true;
    } catch (Exception e) {
        return false;
    }
    return false;
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectContent(com.vmware.vim25.ObjectContent) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) ArrayList(java.util.ArrayList) WebServiceException(javax.xml.ws.WebServiceException)

Example 28 with ObjectSpec

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

Example 29 with ObjectSpec

use of com.vmware.vim25.ObjectSpec 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 30 with ObjectSpec

use of com.vmware.vim25.ObjectSpec 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)60 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)60 PropertySpec (com.vmware.vim25.PropertySpec)60 TraversalSpec (com.vmware.vim25.TraversalSpec)47 ObjectContent (com.vmware.vim25.ObjectContent)40 ArrayList (java.util.ArrayList)33 DynamicProperty (com.vmware.vim25.DynamicProperty)19 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)11 SelectionSpec (com.vmware.vim25.SelectionSpec)11 Gson (com.google.gson.Gson)10 Pair (com.cloud.utils.Pair)4 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)2 CustomFieldStringValue (com.vmware.vim25.CustomFieldStringValue)2 DVPortgroupConfigInfo (com.vmware.vim25.DVPortgroupConfigInfo)2 ObjectUpdate (com.vmware.vim25.ObjectUpdate)2 PropertyChange (com.vmware.vim25.PropertyChange)2 PropertyFilterUpdate (com.vmware.vim25.PropertyFilterUpdate)2 RetrieveOptions (com.vmware.vim25.RetrieveOptions)2 RetrieveResult (com.vmware.vim25.RetrieveResult)2 UpdateSet (com.vmware.vim25.UpdateSet)2