Java Code Examples for com.vmware.vim25.SelectionSpec#setName()

The following examples show how to use com.vmware.vim25.SelectionSpec#setName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VimUtil.java    From vsphere-automation-sdk-java with MIT License 5 votes vote down vote up
/**
 * @return An array of SelectionSpec covering Datacenter to DatastoreFolder.
 */
private static SelectionSpec[] buildTraversal() {

    // For Folder -> Folder recursion
    SelectionSpec sspecvfolders = new SelectionSpec();
    sspecvfolders.setName("VisitFolders");

    TraversalSpec dcToDf = new TraversalSpec();
    dcToDf.setType("Datacenter");
    dcToDf.setSkip(Boolean.FALSE);
    dcToDf.setPath("datastoreFolder");
    dcToDf.setName("dcToDf");
    dcToDf.getSelectSet().add(sspecvfolders);

    // DC -> DS
    TraversalSpec dcToDs = new TraversalSpec();
    dcToDs.setType("Datacenter");
    dcToDs.setPath("datastore");
    dcToDs.setName("dcToDs");
    dcToDs.setSkip(Boolean.FALSE);

    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(dcToDs);
    sspecarrvf.add(dcToDf);
    sspecarrvf.add(sspecvfolders);

    visitFolders.getSelectSet().addAll(sspecarrvf);
    return new SelectionSpec[] { visitFolders };
}
 
Example 2
Source File: DatacenterMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
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);

}
 
Example 3
Source File: DatacenterMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 4
Source File: DatacenterMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
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);
    }
 
Example 5
Source File: VimUtil.java    From vsphere-automation-sdk-java with MIT License 4 votes vote down vote up
/**
 * Retrieves the cluster managed object reference for the specified cluster
 * name using the vim port type.
 *
 * @param vimPortType
 *
 * @param serviceContent
 *            {@link ServiceContent}
 * @param clusterName
 *            name of the cluster to be searched for.
 * @return {@link ManagedObjectReference}
 * @throws InvalidPropertyFaultMsg
 * @throws RuntimeFaultFaultMsg
 * @throws NotFoundFaultMsg
 */
public static ManagedObjectReference getCluster(VimPortType vimPortType,
        ServiceContent serviceContent, String clusterName)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg,
        NotFoundFaultMsg {

    // Spec to allow recursion on the Folder to Folder traversal
    SelectionSpec folderToFolderSelection = new SelectionSpec();
    folderToFolderSelection.setName("folderToFolder");

    SelectionSpec dcToHostFolderSelection = new SelectionSpec();
    dcToHostFolderSelection.setName("dcToHostFolder");

    // spec to traverse from Datacenter to hostFolder
    TraversalSpec dcToHostFolderTraversal = new TraversalSpec();
    dcToHostFolderTraversal.setName("dcToHostFolder");
    dcToHostFolderTraversal.setPath("hostFolder");
    dcToHostFolderTraversal.setType("Datacenter");
    dcToHostFolderTraversal.getSelectSet().addAll(
            Arrays.asList(new SelectionSpec[] { folderToFolderSelection }));
    dcToHostFolderTraversal.setSkip(false);

    // spec to traverse from Folder to a child folder
    TraversalSpec folderToFolderTraversal = new TraversalSpec();
    folderToFolderTraversal.setName("folderToFolder");
    folderToFolderTraversal.setPath("childEntity");
    folderToFolderTraversal.setType("Folder");
    folderToFolderTraversal.getSelectSet()
            .addAll(Arrays.asList(new SelectionSpec[] {
                folderToFolderSelection, dcToHostFolderSelection }));
    folderToFolderTraversal.setSkip(false);

    PropertySpec propertySpec = new PropertySpec();
    propertySpec.getPathSet()
            .addAll(Arrays.asList(new String[] { "name" }));
    propertySpec.setType("ClusterComputeResource");

    ObjectSpec objectSpec = new ObjectSpec();
    objectSpec.setObj(serviceContent.getRootFolder());
    objectSpec.getSelectSet().addAll(Arrays.asList(new SelectionSpec[] {
        folderToFolderTraversal, dcToHostFolderTraversal }));
    objectSpec.setSkip(false);

    // Create PropertyFilterSpec using the PropertySpec and ObjectPec
    PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpec();
    propertyFilterSpec.getPropSet()
            .addAll(Arrays.asList(new PropertySpec[] { propertySpec }));
    propertyFilterSpec.getObjectSet()
            .addAll(Arrays.asList(new ObjectSpec[] { objectSpec }));

    ManagedObjectReference morPropertyCollector = serviceContent
            .getPropertyCollector();
    List<ObjectContent> objectContents = vimPortType.retrieveProperties(
            morPropertyCollector,
            Arrays.asList(new PropertyFilterSpec[] { propertyFilterSpec }));

    for (ObjectContent objectContent : objectContents) {
        ManagedObjectReference clusterManagedObjectReference = objectContent
                .getObj();
        List<DynamicProperty> dynamicProperties = objectContent
                .getPropSet();
        for (DynamicProperty dynamicProperty : dynamicProperties) {
            if (dynamicProperty.getName().equalsIgnoreCase("name")) {
                if (dynamicProperty.getVal().toString()
                        .equalsIgnoreCase(clusterName)) {
                    return clusterManagedObjectReference;
                }
            }
        }
    }
    throw new NotFoundFaultMsg("Cluster Not Found - " + clusterName,
            new NotFound());
}
 
Example 6
Source File: VimUtil.java    From vsphere-automation-sdk-java with MIT License 4 votes vote down vote up
/**
 * Retrieves the list of hosts of the given cluster.
 *
 * @param vimPort
 *            vimPort
 * @param serviceContent
 *            serviceContent
 * @param cluster
 *            cluster
 * @return the list of hosts of the clusters
 * @throws InvalidPropertyFaultMsg
 * @throws RuntimeFaultFaultMsg
 */
public static List<ManagedObjectReference> getHosts(VimPortType vimPort,
        ServiceContent serviceContent, ManagedObjectReference cluster)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    PropertySpec hostPropSpec = new PropertySpec();
    hostPropSpec.setType("HostSystem");
    hostPropSpec.setAll(false);
    hostPropSpec.getPathSet().addAll(Collections.<String>emptyList());

    TraversalSpec hostTSpec = new TraversalSpec();
    hostTSpec.setType("ComputeResource");
    hostTSpec.setPath("host");
    hostTSpec.setName("hosts");

    final SelectionSpec selectionSpec = new SelectionSpec();
    selectionSpec.setName(hostTSpec.getName());

    hostTSpec.getSelectSet().add(selectionSpec);

    List<ObjectSpec> ospecList = new ArrayList<>();
    ObjectSpec ospec = new ObjectSpec();
    ospec.setObj(cluster);
    ospec.setSkip(true);
    ospec.getSelectSet().addAll(Arrays.asList(hostTSpec));
    ospecList.add(ospec);

    PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpec();
    propertyFilterSpec.getPropSet().addAll(Arrays.asList(hostPropSpec));
    propertyFilterSpec.getObjectSet().addAll(ospecList);

    List<PropertyFilterSpec> listpfs = new ArrayList<>(1);
    listpfs.add(propertyFilterSpec);
    List<ObjectContent> listObjContent = VimUtil
            .retrievePropertiesAllObjects(vimPort,
                    serviceContent.getPropertyCollector(), listpfs);

    List<ManagedObjectReference> hosts = new ArrayList<>();

    if (listObjContent != null) {
        for (ObjectContent oc : listObjContent) {
            hosts.add(oc.getObj());
        }
    }
    return hosts;
}
 
Example 7
Source File: VimUtil.java    From vsphere-automation-sdk-java with MIT License 4 votes vote down vote up
/**
 * Gets the VM TraversalSpec.
 *
 * @return the VM TraversalSpec
 */
private static TraversalSpec getVMTraversalSpec() {
    TraversalSpec vAppToVM = new TraversalSpec();
    vAppToVM.setName("vAppToVM");
    vAppToVM.setType("VirtualApp");
    vAppToVM.setPath("vm");

    TraversalSpec vAppToVApp = new TraversalSpec();
    vAppToVApp.setName("vAppToVApp");
    vAppToVApp.setType("VirtualApp");
    vAppToVApp.setPath("resourcePool");

    SelectionSpec vAppRecursion = new SelectionSpec();
    vAppRecursion.setName("vAppToVApp");

    SelectionSpec vmInVApp = new SelectionSpec();
    vmInVApp.setName("vAppToVM");

    List<SelectionSpec> vAppToVMSS = new ArrayList<SelectionSpec>();
    vAppToVMSS.add(vAppRecursion);
    vAppToVMSS.add(vmInVApp);
    vAppToVApp.getSelectSet().addAll(vAppToVMSS);

    SelectionSpec sSpec = new SelectionSpec();
    sSpec.setName("VisitFolders");

    TraversalSpec dataCenterToVMFolder = new TraversalSpec();
    dataCenterToVMFolder.setName("DataCenterToVMFolder");
    dataCenterToVMFolder.setType("Datacenter");
    dataCenterToVMFolder.setPath("vmFolder");
    dataCenterToVMFolder.setSkip(false);
    dataCenterToVMFolder.getSelectSet().add(sSpec);

    TraversalSpec traversalSpec = new TraversalSpec();
    traversalSpec.setName("VisitFolders");
    traversalSpec.setType("Folder");
    traversalSpec.setPath("childEntity");
    traversalSpec.setSkip(false);
    List<SelectionSpec> sSpecArr = new ArrayList<SelectionSpec>();
    sSpecArr.add(sSpec);
    sSpecArr.add(dataCenterToVMFolder);
    sSpecArr.add(vAppToVM);
    sSpecArr.add(vAppToVApp);
    traversalSpec.getSelectSet().addAll(sSpecArr);
    return traversalSpec;
}
 
Example 8
Source File: DatastoreMO.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
public Pair<DatacenterMO, String> getOwnerDatacenter() throws Exception {
    if (_ownerDc != null)
        return _ownerDc;

    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Datacenter");
    pSpec.getPathSet().add("name");

    TraversalSpec folderParentTraversal = new TraversalSpec();
    folderParentTraversal.setType("Folder");
    folderParentTraversal.setPath("parent");
    folderParentTraversal.setName("folderParentTraversal");
    SelectionSpec sSpec = new SelectionSpec();
    sSpec.setName("folderParentTraversal");
    folderParentTraversal.getSelectSet().add(sSpec);

    TraversalSpec dsParentTraversal = new TraversalSpec();
    dsParentTraversal.setType("Datastore");
    dsParentTraversal.setPath("parent");
    dsParentTraversal.setName("dsParentTraversal");
    dsParentTraversal.getSelectSet().add(folderParentTraversal);

    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(getMor());
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(dsParentTraversal);

    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> pfSpecArr = new ArrayList<>();
    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() != null);
    String dcName = ocs.get(0).getPropSet().get(0).getVal().toString();
    _ownerDc = new Pair<>(new DatacenterMO(_context, ocs.get(0).getObj()), dcName);
    return _ownerDc;
}
 
Example 9
Source File: VmwareClient.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
private SelectionSpec getSelectionSpec(String name) {
    SelectionSpec genericSpec = new SelectionSpec();
    genericSpec.setName(name);
    return genericSpec;
}
 
Example 10
Source File: VMwareUtil.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
private static TraversalSpec getVMTraversalSpec() {
    // Create a TraversalSpec that starts from the 'root' objects
    // and traverses the inventory tree to get to the VirtualMachines.
    // Build the traversal specs bottoms up

    // TraversalSpec to get to the VM in a vApp
    TraversalSpec vAppToVM = new TraversalSpec();

    vAppToVM.setName("vAppToVM");
    vAppToVM.setType("VirtualApp");
    vAppToVM.setPath("vm");

    // TraversalSpec for vApp to vApp
    TraversalSpec vAppToVApp = new TraversalSpec();

    vAppToVApp.setName("vAppToVApp");
    vAppToVApp.setType("VirtualApp");
    vAppToVApp.setPath("resourcePool");

    // SelectionSpec for vApp-to-vApp recursion
    SelectionSpec vAppRecursion = new SelectionSpec();

    vAppRecursion.setName("vAppToVApp");

    // SelectionSpec to get to a VM in the vApp
    SelectionSpec vmInVApp = new SelectionSpec();

    vmInVApp.setName("vAppToVM");

    // SelectionSpec for both vApp to vApp and vApp to VM
    List<SelectionSpec> vAppToVMSS = new ArrayList<>();

    vAppToVMSS.add(vAppRecursion);
    vAppToVMSS.add(vmInVApp);

    vAppToVApp.getSelectSet().addAll(vAppToVMSS);

    // This SelectionSpec is used for recursion for Folder recursion
    SelectionSpec sSpec = new SelectionSpec();

    sSpec.setName("VisitFolders");

    // Traversal to get to the vmFolder from DataCenter
    TraversalSpec dataCenterToVMFolder = new TraversalSpec();

    dataCenterToVMFolder.setName("DataCenterToVMFolder");
    dataCenterToVMFolder.setType("Datacenter");
    dataCenterToVMFolder.setPath("vmFolder");
    dataCenterToVMFolder.setSkip(false);

    dataCenterToVMFolder.getSelectSet().add(sSpec);

    // TraversalSpec to get to the DataCenter from rootFolder
    TraversalSpec traversalSpec = new TraversalSpec();

    traversalSpec.setName("VisitFolders");
    traversalSpec.setType("Folder");
    traversalSpec.setPath("childEntity");
    traversalSpec.setSkip(false);

    List<SelectionSpec> sSpecArr = new ArrayList<>();

    sSpecArr.add(sSpec);
    sSpecArr.add(dataCenterToVMFolder);
    sSpecArr.add(vAppToVM);
    sSpecArr.add(vAppToVApp);

    traversalSpec.getSelectSet().addAll(sSpecArr);

    return traversalSpec;
}