Search in sources :

Example 21 with TraversalSpec

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

the class HostDatastoreSystemMO method getStorageTraversalSpec.

private SelectionSpec[] getStorageTraversalSpec() {
    // create a traversal spec that start from root folder
    SelectionSpec ssFolders = new SelectionSpec();
    ssFolders.setName("visitFolders");
    TraversalSpec datacenterSpec = new TraversalSpec();
    datacenterSpec.setName("dcTodf");
    datacenterSpec.setType("Datacenter");
    datacenterSpec.setPath("datastoreFolder");
    datacenterSpec.setSkip(Boolean.FALSE);
    datacenterSpec.getSelectSet().add(ssFolders);
    TraversalSpec visitFolder = new TraversalSpec();
    visitFolder.setType("Folder");
    visitFolder.setName("visitFolders");
    visitFolder.setPath("childEntity");
    visitFolder.setSkip(Boolean.FALSE);
    List<SelectionSpec> ssSpecList = new ArrayList<SelectionSpec>();
    ssSpecList.add(datacenterSpec);
    ssSpecList.add(ssFolders);
    visitFolder.getSelectSet().addAll(ssSpecList);
    return (new SelectionSpec[] { visitFolder });
}
Also used : SelectionSpec(com.vmware.vim25.SelectionSpec) TraversalSpec(com.vmware.vim25.TraversalSpec) ArrayList(java.util.ArrayList)

Example 22 with TraversalSpec

use of com.vmware.vim25.TraversalSpec 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 23 with TraversalSpec

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

the class HostMO 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 host2DatastoreTraversal = new TraversalSpec();
    host2DatastoreTraversal.setType("HostSystem");
    host2DatastoreTraversal.setPath("datastore");
    host2DatastoreTraversal.setName("host2DatastoreTraversal");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(host2DatastoreTraversal);
    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 24 with TraversalSpec

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

the class VmwareClient method constructCompleteTraversalSpec.

/*
     * @return An array of SelectionSpec covering VM, Host, Resource pool,
     * Cluster Compute Resource and Datastore.
     */
private List<SelectionSpec> constructCompleteTraversalSpec() {
    // ResourcePools to VM: RP -> VM
    TraversalSpec rpToVm = new TraversalSpec();
    rpToVm.setName("rpToVm");
    rpToVm.setType("ResourcePool");
    rpToVm.setPath("vm");
    rpToVm.setSkip(Boolean.FALSE);
    // VirtualApp to VM: vApp -> VM
    TraversalSpec vAppToVM = new TraversalSpec();
    vAppToVM.setName("vAppToVM");
    vAppToVM.setType("VirtualApp");
    vAppToVM.setPath("vm");
    // Host to VM: HostSystem -> VM
    TraversalSpec hToVm = new TraversalSpec();
    hToVm.setType("HostSystem");
    hToVm.setPath("vm");
    hToVm.setName("hToVm");
    hToVm.getSelectSet().add(getSelectionSpec("VisitFolders"));
    hToVm.setSkip(Boolean.FALSE);
    // DataCenter to DataStore: DC -> DS
    TraversalSpec dcToDs = new TraversalSpec();
    dcToDs.setType("Datacenter");
    dcToDs.setPath("datastore");
    dcToDs.setName("dcToDs");
    dcToDs.setSkip(Boolean.FALSE);
    // Recurse through all ResourcePools
    TraversalSpec rpToRp = new TraversalSpec();
    rpToRp.setType("ResourcePool");
    rpToRp.setPath("resourcePool");
    rpToRp.setSkip(Boolean.FALSE);
    rpToRp.setName("rpToRp");
    rpToRp.getSelectSet().add(getSelectionSpec("rpToRp"));
    TraversalSpec crToRp = new TraversalSpec();
    crToRp.setType("ComputeResource");
    crToRp.setPath("resourcePool");
    crToRp.setSkip(Boolean.FALSE);
    crToRp.setName("crToRp");
    crToRp.getSelectSet().add(getSelectionSpec("rpToRp"));
    TraversalSpec crToH = new TraversalSpec();
    crToH.setSkip(Boolean.FALSE);
    crToH.setType("ComputeResource");
    crToH.setPath("host");
    crToH.setName("crToH");
    TraversalSpec dcToHf = new TraversalSpec();
    dcToHf.setSkip(Boolean.FALSE);
    dcToHf.setType("Datacenter");
    dcToHf.setPath("hostFolder");
    dcToHf.setName("dcToHf");
    dcToHf.getSelectSet().add(getSelectionSpec("VisitFolders"));
    TraversalSpec vAppToRp = new TraversalSpec();
    vAppToRp.setName("vAppToRp");
    vAppToRp.setType("VirtualApp");
    vAppToRp.setPath("resourcePool");
    vAppToRp.getSelectSet().add(getSelectionSpec("rpToRp"));
    TraversalSpec dcToVmf = new TraversalSpec();
    dcToVmf.setType("Datacenter");
    dcToVmf.setSkip(Boolean.FALSE);
    dcToVmf.setPath("vmFolder");
    dcToVmf.setName("dcToVmf");
    dcToVmf.getSelectSet().add(getSelectionSpec("VisitFolders"));
    // For Folder -> Folder recursion
    TraversalSpec visitFolders = new TraversalSpec();
    visitFolders.setType("Folder");
    visitFolders.setPath("childEntity");
    visitFolders.setSkip(Boolean.FALSE);
    visitFolders.setName("VisitFolders");
    List<SelectionSpec> sspecarrvf = new ArrayList<SelectionSpec>();
    sspecarrvf.add(getSelectionSpec("crToRp"));
    sspecarrvf.add(getSelectionSpec("crToH"));
    sspecarrvf.add(getSelectionSpec("dcToVmf"));
    sspecarrvf.add(getSelectionSpec("dcToHf"));
    sspecarrvf.add(getSelectionSpec("vAppToRp"));
    sspecarrvf.add(getSelectionSpec("vAppToVM"));
    sspecarrvf.add(getSelectionSpec("dcToDs"));
    sspecarrvf.add(getSelectionSpec("hToVm"));
    sspecarrvf.add(getSelectionSpec("rpToVm"));
    sspecarrvf.add(getSelectionSpec("VisitFolders"));
    visitFolders.getSelectSet().addAll(sspecarrvf);
    List<SelectionSpec> resultspec = new ArrayList<SelectionSpec>();
    resultspec.add(visitFolders);
    resultspec.add(crToRp);
    resultspec.add(crToH);
    resultspec.add(dcToVmf);
    resultspec.add(dcToHf);
    resultspec.add(vAppToRp);
    resultspec.add(vAppToVM);
    resultspec.add(dcToDs);
    resultspec.add(hToVm);
    resultspec.add(rpToVm);
    resultspec.add(rpToRp);
    return resultspec;
}
Also used : TraversalSpec(com.vmware.vim25.TraversalSpec) SelectionSpec(com.vmware.vim25.SelectionSpec) ArrayList(java.util.ArrayList)

Example 25 with TraversalSpec

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

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