Java 类com.vmware.vim25.TraversalSpec 实例源码

项目:GraphiteReceiver    文件:Utils.java   
private static TraversalSpec getTraversalSpec(String clusterName){
    TraversalSpec traversalSpec = new TraversalSpec();
    traversalSpec.setName("traverseEntities");
    traversalSpec.setPath("view");
    traversalSpec.setSkip(false);
    traversalSpec.setType("ContainerView");

    TraversalSpec traversalSpecAux = new TraversalSpec();
    if(clusterName == null){
        traversalSpecAux.setType("ComputeResource");
        traversalSpecAux.setPath("host");
    }else{
        traversalSpecAux.setType("HostSystem");
        traversalSpecAux.setPath("vm");
    }
    traversalSpecAux.setSkip(false);
    traversalSpec.getSelectSet().add(traversalSpecAux);
    return traversalSpec;
}
项目:cloudstack    文件:HostDatastoreSystemMO.java   
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);
    }
项目:cloudstack    文件:DatacenterMO.java   
public List<ObjectContent> getDatastorePropertiesOnDatacenter(String[] propertyPaths) throws Exception {

        PropertySpec pSpec = new PropertySpec();
        pSpec.setType("Datastore");
        pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));

        TraversalSpec dc2DatastoreTraversal = new TraversalSpec();
        dc2DatastoreTraversal.setType("Datacenter");
        dc2DatastoreTraversal.setPath("datastore");
        dc2DatastoreTraversal.setName("dc2DatastoreTraversal");

        ObjectSpec oSpec = new ObjectSpec();
        oSpec.setObj(_mor);
        oSpec.setSkip(Boolean.TRUE);
        oSpec.getSelectSet().add(dc2DatastoreTraversal);

        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);

    }
项目:photon-model    文件:Finder.java   
private List<ObjectContent> ancestrySet(ManagedObjectReference ref)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ObjectSpec ospec = new ObjectSpec();
    ospec.setObj(ref);
    ospec.setSkip(false);

    TraversalSpec tspec = new TraversalSpec();
    tspec.setSkip(false);
    tspec.setPath("parent");
    tspec.setType("ManagedEntity");
    tspec.setName("traverseParent");

    SelectionSpec selSpec = new SelectionSpec();
    selSpec.setName("traverseParent");

    tspec.getSelectSet().add(selSpec);

    ospec.getSelectSet().add(tspec);

    PropertySpec pspec = new PropertySpec();
    pspec.setType("ManagedEntity");
    pspec.getPathSet().add("name");
    pspec.getPathSet().add("parent");

    PropertyFilterSpec filter = new PropertyFilterSpec();
    filter.getObjectSet().add(ospec);
    filter.getPropSet().add(pspec);

    return this.connection.getVimPort()
            .retrieveProperties(this.connection.getServiceContent().getPropertyCollector(),
                    Collections.singletonList(filter));

}
项目:photon-model    文件:Lister.java   
private List<Element> listResourcePool()
        throws FinderException, InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ObjectSpec ospec = new ObjectSpec();
    ospec.setObj(this.start);
    ospec.setSkip(true);

    for (String f : new String[] { "resourcePool" }) {
        TraversalSpec tspec = new TraversalSpec();
        tspec.setPath(f);
        tspec.setSkip(false);
        tspec.setType("ResourcePool");

        ospec.getSelectSet().add(tspec);
    }

    List<PropertySpec> pspecs = new ArrayList<>();
    for (String t : new String[] { "ResourcePool" }) {
        PropertySpec pspec = new PropertySpec();
        pspec.setType(t);
        pspec.getPathSet().add("name");

        pspecs.add(pspec);
    }

    PropertyFilterSpec spec = new PropertyFilterSpec();
    spec.getObjectSet().add(ospec);
    spec.getPropSet().addAll(pspecs);

    return callPropertyCollectorAndConvert(spec);
}
项目:photon-model    文件:Lister.java   
private List<Element> listComputeResource()
        throws FinderException, InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ObjectSpec ospec = new ObjectSpec();
    ospec.setSkip(true);
    ospec.setObj(this.start);

    for (String f : new String[] { "host", "resourcePool" }) {
        TraversalSpec tspec = new TraversalSpec();
        tspec.setPath(f);
        tspec.setType("ComputeResource");
        tspec.setSkip(false);

        ospec.getSelectSet().add(tspec);
    }

    PropertyFilterSpec filter = new PropertyFilterSpec();
    filter.getObjectSet().add(ospec);

    for (String t : new String[] { "HostSystem", "ResourcePool" }) {
        PropertySpec pspec = new PropertySpec();
        pspec.setType(t);
        pspec.getPathSet().add("name");

        filter.getPropSet().add(pspec);
    }

    return callPropertyCollectorAndConvert(filter);
}
项目:photon-model    文件:Lister.java   
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" };

    for (String f : fields) {
        TraversalSpec tspec = new TraversalSpec();
        tspec.setPath(f);
        tspec.setSkip(false);
        tspec.setType("Datacenter");

        ospec.getSelectSet().add(tspec);
    }

    PropertySpec pspec = new PropertySpec();
    pspec.setType("Folder");
    pspec.getPathSet().add("name");

    PropertyFilterSpec spec = new PropertyFilterSpec();
    spec.getObjectSet().add(ospec);
    spec.getPropSet().add(pspec);

    return callPropertyCollectorAndConvert(spec);
}
项目:vsphere-automation-sdk-java    文件:VimUtil.java   
/**
 * @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 };
}
项目:cloudstack    文件:HostMO.java   
public ManagedObjectReference getNetworkMor(String portGroupName) throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Network");
    pSpec.getPathSet().add("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.getSelectSet().add(host2NetworkTraversal);

    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.getVal().equals(portGroupName))
                        return oc.getObj();
                }
            }
        }
    }
    return null;
}
项目:cloudstack    文件:HostMO.java   
@Override
public ObjectContent[] getVmPropertiesOnHyperHost(String[] propertyPaths) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - retrieveProperties() for VM properties. target MOR: " + _mor.getValue() + ", properties: " +
                new Gson().toJson(propertyPaths));

    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("VirtualMachine");
    pSpec.getPathSet().addAll(Arrays.asList(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.getSelectSet().add(host2VmTraversal);

    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()]);
}
项目:cloudstack    文件:HostMO.java   
@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()]);
}
项目:cloudstack    文件:DatacenterMO.java   
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);

}
项目:cloudstack    文件:DatacenterMO.java   
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);
}
项目:cloudstack    文件:DatacenterMO.java   
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);
    }
项目:cloudstack    文件:DatacenterMO.java   
public ManagedObjectReference getDvPortGroupMor(String dvPortGroupName) throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("DistributedVirtualPortgroup");
    pSpec.getPathSet().add("name");

    TraversalSpec datacenter2DvPortGroupTraversal = new TraversalSpec();
    datacenter2DvPortGroupTraversal.setType("Datacenter");
    datacenter2DvPortGroupTraversal.setPath("network");
    datacenter2DvPortGroupTraversal.setName("datacenter2DvPortgroupTraversal");

    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(datacenter2DvPortGroupTraversal);

    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.getVal().equals(dvPortGroupName))
                        return oc.getObj();
                }
            }
        }
    }
    return null;
}
项目:cloudstack    文件:VirtualMachineMO.java   
public Pair<DatastoreMO, String> getOwnerDatastore(String dsFullPath) throws Exception {
    String dsName = DatastoreFile.getDatastoreNameFromPath(dsFullPath);

    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Datastore");
    pSpec.getPathSet().add("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.getSelectSet().add(vmDatastoreTraversal);

    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) {
            DynamicProperty prop = oc.getPropSet().get(0);
            if (prop.getVal().toString().equals(dsName)) {
                return new Pair<DatastoreMO, String>(new DatastoreMO(_context, oc.getObj()), dsName);
            }
        }
    }

    return null;
}
项目:cloudstack    文件:VirtualMachineMO.java   
public String[] getNetworks() throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Network");
    pSpec.getPathSet().add("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.getSelectSet().add(vm2NetworkTraversal);

    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);

    List<String> networks = new ArrayList<String>();
    if (ocs != null && ocs.size() > 0) {
        for (ObjectContent oc : ocs) {
            networks.add(oc.getPropSet().get(0).getVal().toString());
        }
    }
    return networks.toArray(new String[0]);
}
项目:cloudstack    文件:ClusterMO.java   
@Override
public ObjectContent[] getVmPropertiesOnHyperHost(String[] propertyPaths) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - retrieveProperties() for VM properties. target MOR: " + _mor.getValue() + ", properties: " + new Gson().toJson(propertyPaths));

    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("VirtualMachine");
    pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));

    TraversalSpec host2VmFolderTraversal = new TraversalSpec();
    host2VmFolderTraversal.setType("HostSystem");
    host2VmFolderTraversal.setPath("vm");
    host2VmFolderTraversal.setName("host2VmFolderTraversal");

    TraversalSpec cluster2HostFolderTraversal = new TraversalSpec();
    cluster2HostFolderTraversal.setType("ClusterComputeResource");
    cluster2HostFolderTraversal.setPath("host");
    cluster2HostFolderTraversal.setName("cluster2HostFolderTraversal");
    cluster2HostFolderTraversal.getSelectSet().add(host2VmFolderTraversal);

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

    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()]);
}
项目:cloudstack    文件:ClusterMO.java   
@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 cluster2DatastoreTraversal = new TraversalSpec();
    cluster2DatastoreTraversal.setType("ClusterComputeResource");
    cluster2DatastoreTraversal.setPath("datastore");
    cluster2DatastoreTraversal.setName("cluster2DatastoreTraversal");

    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(cluster2DatastoreTraversal);

    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()]);
}
项目:cloudstack    文件:ClusterMO.java   
public ObjectContent[] getHostPropertiesOnCluster(String[] propertyPaths) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - retrieveProperties() on Host properties. target MOR: " + _mor.getValue() + ", properties: " + new Gson().toJson(propertyPaths));

    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("HostSystem");
    pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));

    TraversalSpec cluster2HostTraversal = new TraversalSpec();
    cluster2HostTraversal.setType("ClusterComputeResource");
    cluster2HostTraversal.setPath("host");
    cluster2HostTraversal.setName("cluster2HostTraversal");

    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(cluster2HostTraversal);

    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()]);
}
项目:photon-model    文件:Lister.java   
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);
}
项目:photon-model    文件:DatacenterLister.java   
public List<Element> listAllDatacenters() throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    PropertyFilterSpec spec = new PropertyFilterSpec();

    ObjectSpec ospec = new ObjectSpec();
    ospec.setObj(connection.getServiceContent().getRootFolder());
    ospec.setSkip(false);
    spec.getObjectSet().add(ospec);

    TraversalSpec traverseFolders = new TraversalSpec();
    traverseFolders.setPath("childEntity");
    traverseFolders.setSkip(false);
    String traversalName = "folder2child";
    traverseFolders.setName(traversalName);
    traverseFolders.setType(VimNames.TYPE_FOLDER);

    SelectionSpec selSpec = new SelectionSpec();
    selSpec.setName(traversalName);
    traverseFolders.getSelectSet().add(selSpec);

    ospec.getSelectSet().add(traverseFolders);

    for (String t : new String[] { VimNames.TYPE_FOLDER, VimNames.TYPE_DATACENTER }) {
        PropertySpec pspec = new PropertySpec();
        pspec.setType(t);
        pspec.getPathSet().add(VimNames.PROPERTY_NAME);
        pspec.getPathSet().add(VimNames.PROPERTY_PARENT);

        spec.getPropSet().add(pspec);
    }

    List<ObjectContent> ocs = retrieveProperties(spec);
    List<Element> res = new ArrayList<>();

    for (ObjectContent oc : ocs) {
        if (oc.getObj().getType().equals(VimNames.TYPE_FOLDER)) {
            continue;
        }

        String parentPath = buildPathToParent(prop(oc, VimNames.PROPERTY_PARENT), ocs);
        res.add(Element.make(oc.getObj(), parentPath + "/" + prop(oc, VimNames.PROPERTY_NAME)));
    }

    return res;
}
项目:photon-model    文件:GetMoRef.java   
/**
 * Get the MOR of the Virtual Machine by its name.
 *
 * @param vmName           The name of the Virtual Machine
 * @param propCollectorRef
 * @return The Managed Object reference for this VM
 * @throws RuntimeFaultFaultMsg
 * @throws InvalidPropertyFaultMsg
 */
public ManagedObjectReference vmByVMname(
        final String vmName, final ManagedObjectReference propCollectorRef
) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {

    init();

    ManagedObjectReference rootFolder = this.serviceContent.getRootFolder();
    TraversalSpec tSpec = getVMTraversalSpec();
    // Create Property Spec
    PropertySpec propertySpec = new PropertySpecBuilder()
            .all(Boolean.FALSE)
            .pathSet("name")
            .type("VirtualMachine");

    // Now create Object Spec
    ObjectSpec objectSpec = new ObjectSpecBuilder()
            .obj(rootFolder)
            .skip(Boolean.TRUE)
            .selectSet(tSpec);

    // Create PropertyFilterSpec using the PropertySpec and ObjectPec
    // created above.
    PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpecBuilder()
            .propSet(propertySpec)
            .objectSet(objectSpec);

    List<PropertyFilterSpec> listpfs =
            new ArrayList<PropertyFilterSpec>(1);
    listpfs.add(propertyFilterSpec);
    RetrieveOptions options = new RetrieveOptions();
    // Query returns a fixed number of results
    // if token is returned we can get more results
    RetrieveResult retrieveResult =
            this.vimPort.retrievePropertiesEx(propCollectorRef, listpfs, options);
    String token = null;

    do {
        token = (retrieveResult != null) ? retrieveResult.getToken() : null;
        List<ObjectContent> listobcont =
                (retrieveResult != null) ?
                        retrieveResult.getObjects() : null;

        if (listobcont != null) {
            for (ObjectContent oc : listobcont) {
                ManagedObjectReference mr = oc.getObj();
                String vmnm = null;
                List<DynamicProperty> dps = oc.getPropSet();
                if (dps != null) {
                    for (DynamicProperty dp : dps) {
                        vmnm = (String) dp.getVal();
                        if (vmName.equals(vmnm)) {
                            return mr;
                        }
                    }
                }
            }
        }
        if (token != null) {
            retrieveResult = this.vimPort.continueRetrievePropertiesEx(propCollectorRef, token);
        }
    } while (token != null);

    return null;
}
项目:photon-model    文件:GetMoRef.java   
/**
 * @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
            );
}
项目:vsphere-automation-sdk-java    文件:VimUtil.java   
/**
 * 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;
}
项目:vsphere-automation-sdk-java    文件:VimUtil.java   
/**
 * Retrieves the vm managed object reference for the specified vm name using
 * the vim port type.
 *
 * @param vimPortType
 * @param serviceContent
 * @param vmname
 * @return
 * @throws NotFoundFaultMsg
 * @throws RuntimeFaultFaultMsg
 * @throws InvalidPropertyFaultMsg
 */
public static ManagedObjectReference getVM(VimPortType vimPortType,
        ServiceContent serviceContent, String vmname)
        throws NotFoundFaultMsg, InvalidPropertyFaultMsg,
        RuntimeFaultFaultMsg {
    ManagedObjectReference propCollectorRef = serviceContent
            .getPropertyCollector();
    ManagedObjectReference rootFolderRef = serviceContent.getRootFolder();

    ManagedObjectReference retVmRef = null;
    TraversalSpec tSpec = getVMTraversalSpec();

    PropertySpec propertySpec = new PropertySpec();
    propertySpec.setAll(Boolean.FALSE);
    propertySpec.getPathSet().add("name");
    propertySpec.setType("VirtualMachine");

    ObjectSpec objectSpec = new ObjectSpec();
    objectSpec.setObj(rootFolderRef);
    objectSpec.setSkip(Boolean.TRUE);
    objectSpec.getSelectSet().add(tSpec);

    PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpec();
    propertyFilterSpec.getPropSet().add(propertySpec);
    propertyFilterSpec.getObjectSet().add(objectSpec);

    List<PropertyFilterSpec> listpfs = new ArrayList<PropertyFilterSpec>(1);
    listpfs.add(propertyFilterSpec);
    List<ObjectContent> listobjcont = retrievePropertiesAllObjects(
            vimPortType, propCollectorRef, listpfs);

    if (listobjcont != null) {
        for (ObjectContent oc : listobjcont) {
            ManagedObjectReference mr = oc.getObj();
            String vmnm = null;
            List<DynamicProperty> dps = oc.getPropSet();
            if (dps != null) {
                for (DynamicProperty dp : dps) {
                    vmnm = (String) dp.getVal();
                }
            }
            if (vmnm != null && vmnm.equals(vmname)) {
                retVmRef = mr;
                break;
            }
        }
    }
    if (retVmRef == null) {
        throw new NotFoundFaultMsg("VM Not Found - " + vmname,
                new NotFound());
    }
    return retVmRef;
}
项目:vsphere-automation-sdk-java    文件:VimUtil.java   
/**
 * 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;
}
项目:cloudstack    文件:DatastoreMO.java   
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;
}
项目:cloudstack    文件:DatacenterMO.java   
public ManagedObjectReference getDvSwitchMor(ManagedObjectReference dvPortGroupMor) throws Exception {
    String dvPortGroupKey = null;
    ManagedObjectReference dvSwitchMor = null;
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("DistributedVirtualPortgroup");
    pSpec.getPathSet().add("key");
    pSpec.getPathSet().add("config.distributedVirtualSwitch");

    TraversalSpec datacenter2DvPortGroupTraversal = new TraversalSpec();
    datacenter2DvPortGroupTraversal.setType("Datacenter");
    datacenter2DvPortGroupTraversal.setPath("network");
    datacenter2DvPortGroupTraversal.setName("datacenter2DvPortgroupTraversal");

    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(datacenter2DvPortGroupTraversal);

    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) {
                assert (props.size() == 2);
                for (DynamicProperty prop : props) {
                    if (prop.getName().equals("key")) {
                        dvPortGroupKey = (String)prop.getVal();
                    } else {
                        dvSwitchMor = (ManagedObjectReference)prop.getVal();
                    }
                }
                if ((dvPortGroupKey != null) && dvPortGroupKey.equals(dvPortGroupMor.getValue())) {
                    return dvSwitchMor;
                }
            }
        }
    }
    return null;
}
项目:cloudstack    文件:VMwareUtil.java   
public static Map<String, ManagedObjectReference> getVms(VMwareConnection connection) throws Exception {
    Map<String, ManagedObjectReference> nameToVm = new HashMap<>();

    ManagedObjectReference rootFolder = connection.getServiceContent().getRootFolder();

    TraversalSpec tSpec = getVMTraversalSpec();

    PropertySpec propertySpec = new PropertySpec();

    propertySpec.setAll(Boolean.FALSE);
    propertySpec.getPathSet().add("name");
    propertySpec.setType("VirtualMachine");

    ObjectSpec objectSpec = new ObjectSpec();

    objectSpec.setObj(rootFolder);
    objectSpec.setSkip(Boolean.TRUE);
    objectSpec.getSelectSet().add(tSpec);

    PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpec();

    propertyFilterSpec.getPropSet().add(propertySpec);
    propertyFilterSpec.getObjectSet().add(objectSpec);

    List<PropertyFilterSpec> lstPfs = new ArrayList<>(1);

    lstPfs.add(propertyFilterSpec);

    VimPortType vimPortType = connection.getVimPortType();
    ManagedObjectReference propertyCollector = connection.getServiceContent().getPropertyCollector();

    List<ObjectContent> lstObjectContent = retrievePropertiesAllObjects(lstPfs, vimPortType, propertyCollector);

    if (lstObjectContent != null) {
        for (ObjectContent oc : lstObjectContent) {
            ManagedObjectReference mor = oc.getObj();
            List<DynamicProperty> dps = oc.getPropSet();
            String vmName = null;

            if (dps != null) {
                for (DynamicProperty dp : dps) {
                    vmName = (String)dp.getVal();
                }
            }

            if (vmName != null) {
                nameToVm.put(vmName, mor);
            }
        }
    }

    return nameToVm;
}
项目:cloudstack    文件:VMwareUtil.java   
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;
}