Search in sources :

Example 26 with Folder

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

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.setPathSet(new String[] { "name" });
    TraversalSpec folderParentTraversal = new TraversalSpec();
    folderParentTraversal.setType("Folder");
    folderParentTraversal.setPath("parent");
    folderParentTraversal.setName("folderParentTraversal");
    folderParentTraversal.setSelectSet(new SelectionSpec[] { new SelectionSpec(null, null, "folderParentTraversal") });
    TraversalSpec dsParentTraversal = new TraversalSpec();
    dsParentTraversal.setType("Datastore");
    dsParentTraversal.setPath("parent");
    dsParentTraversal.setName("dsParentTraversal");
    dsParentTraversal.setSelectSet(new SelectionSpec[] { folderParentTraversal });
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(getMor());
    oSpec.setSkip(Boolean.TRUE);
    oSpec.setSelectSet(new SelectionSpec[] { dsParentTraversal });
    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() != null);
    String dcName = ocs[0].getPropSet()[0].getVal().toString();
    _ownerDc = new Pair<DatacenterMO, String>(new DatacenterMO(_context, ocs[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)

Example 27 with Folder

use of com.vmware.vim25.mo.Folder in project coprhd-controller by CoprHD.

the class VCenterAPI method getRootFolder.

/**
 * Gets the root folder.
 *
 * @return the root folder.
 */
public Folder getRootFolder() {
    checkConnected();
    Folder rootFolder = service.getRootFolder();
    return rootFolder;
}
Also used : Folder(com.vmware.vim25.mo.Folder)

Example 28 with Folder

use of com.vmware.vim25.mo.Folder in project photon-model by vmware.

the class GetMoRef method getVMTraversalSpec.

/**
 * @return TraversalSpec specification to get to the VirtualMachine managed
 *         object.
 */
public TraversalSpec getVMTraversalSpec() {
    // Create a traversal spec that starts from the 'root' objects
    // and traverses the inventory tree to get to the VirtualMachines.
    // Build the traversal specs bottoms up
    // Traversal to get to the VM in a VApp
    TraversalSpec vAppToVM = new TraversalSpecBuilder().name("vAppToVM").type("VirtualApp").path("vm");
    // Traversal spec for VApp to VApp
    TraversalSpec vAppToVApp = new TraversalSpecBuilder().name("vAppToVApp").type("VirtualApp").path("resourcePool").selectSet(// SelectionSpec for both VApp to VApp and VApp to VM
    new SelectionSpecBuilder().name("vAppToVApp"), new SelectionSpecBuilder().name("vAppToVM"));
    // This SelectionSpec is used for recursion for Folder recursion
    SelectionSpec visitFolders = new SelectionSpecBuilder().name("VisitFolders");
    // Traversal to get to the vmFolder from DataCenter
    TraversalSpec dataCenterToVMFolder = new TraversalSpecBuilder().name("DataCenterToVMFolder").type("Datacenter").path("vmFolder").skip(false).selectSet(visitFolders);
    // TraversalSpec to get to the DataCenter from rootFolder
    return new TraversalSpecBuilder().name("VisitFolders").type("Folder").path("childEntity").skip(false).selectSet(visitFolders, dataCenterToVMFolder, vAppToVM, vAppToVApp);
}
Also used : TraversalSpec(com.vmware.vim25.TraversalSpec) SelectionSpec(com.vmware.vim25.SelectionSpec) TraversalSpecBuilder(com.vmware.photon.controller.model.adapters.vsphere.util.builders.TraversalSpecBuilder) SelectionSpecBuilder(com.vmware.photon.controller.model.adapters.vsphere.util.builders.SelectionSpecBuilder)

Example 29 with Folder

use of com.vmware.vim25.mo.Folder in project photon-model by vmware.

the class Lister method listFolder.

private List<Element> listFolder() throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, FinderException {
    PropertyFilterSpec spec = new PropertyFilterSpec();
    ObjectSpec objSpec = new ObjectSpec();
    objSpec.setObj(this.start);
    TraversalSpec selectionSpec = new TraversalSpec();
    selectionSpec.setPath("childEntity");
    selectionSpec.setType("Folder");
    selectionSpec.setSkip(false);
    objSpec.getSelectSet().add(selectionSpec);
    spec.getObjectSet().add(objSpec);
    // Retrieve all objects that we can deal with
    String[] childTypes = { "Folder", "Datacenter", "VirtualMachine", "Network", "ComputeResource", "ClusterComputeResource", "Datastore" };
    for (String t : childTypes) {
        PropertySpec pspec = new PropertySpec();
        pspec.setType(t);
        pspec.getPathSet().add("name");
        // Additional basic properties.
        if (t.equals("ComputeResource") || t.equals("ClusterComputeResource")) {
            // The ComputeResource and ClusterComputeResource are dereferenced in
            // the ResourcePoolFlag. Make sure they always have their resourcePool
            // field populated.
            pspec.getPathSet().add("resourcePool");
        }
        spec.getPropSet().add(pspec);
    }
    return callPropertyCollectorAndConvert(spec);
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec)

Example 30 with Folder

use of com.vmware.vim25.mo.Folder in project photon-model by vmware.

the class Lister method listDatacenter.

private List<Element> listDatacenter() throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, FinderException {
    ObjectSpec ospec = new ObjectSpec();
    ospec.setObj(this.start);
    ospec.setSkip(true);
    // Include every datastore folder in the select set
    String[] fields = { "vmFolder", "hostFolder", "datastoreFolder", "networkFolder", "datastore" };
    for (String f : fields) {
        TraversalSpec tspec = new TraversalSpec();
        tspec.setPath(f);
        tspec.setSkip(false);
        tspec.setType(VimNames.TYPE_DATACENTER);
        ospec.getSelectSet().add(tspec);
    }
    PropertySpec pspec = new PropertySpec();
    pspec.setType(VimNames.TYPE_FOLDER);
    pspec.getPathSet().add(VimNames.PROPERTY_NAME);
    PropertySpec dcspec = new PropertySpec();
    dcspec.setType(VimNames.TYPE_DATACENTER);
    dcspec.getPathSet().add(VimNames.PROPERTY_NAME);
    PropertySpec dsspec = new PropertySpec();
    dsspec.setType(VimNames.TYPE_DATASTORE);
    dsspec.getPathSet().add(VimNames.PROPERTY_NAME);
    PropertyFilterSpec spec = new PropertyFilterSpec();
    spec.getObjectSet().add(ospec);
    spec.getPropSet().add(pspec);
    spec.getPropSet().add(dcspec);
    spec.getPropSet().add(dsspec);
    return callPropertyCollectorAndConvert(spec);
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec)

Aggregations

ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)30 TraversalSpec (com.vmware.vim25.TraversalSpec)15 ArrayList (java.util.ArrayList)15 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)13 SelectionSpec (com.vmware.vim25.SelectionSpec)12 ObjectSpec (com.vmware.vim25.ObjectSpec)11 PropertySpec (com.vmware.vim25.PropertySpec)11 TaskInfo (com.vmware.vim25.TaskInfo)10 RemoteException (java.rmi.RemoteException)9 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)8 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)8 InvalidPropertyFaultMsg (com.vmware.vim25.InvalidPropertyFaultMsg)8 RuntimeFaultFaultMsg (com.vmware.vim25.RuntimeFaultFaultMsg)8 VirtualDisk (com.vmware.vim25.VirtualDisk)7 Operation (com.vmware.xenon.common.Operation)7 VimNames (com.vmware.photon.controller.model.adapters.vsphere.util.VimNames)6 PhotonModelUriUtils (com.vmware.photon.controller.model.util.PhotonModelUriUtils)6 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)6 VirtualMachineDefinedProfileSpec (com.vmware.vim25.VirtualMachineDefinedProfileSpec)6 VirtualMachineRelocateSpec (com.vmware.vim25.VirtualMachineRelocateSpec)6