Java Code Examples for com.vmware.vim25.TraversalSpec#setType()
The following examples show how to use
com.vmware.vim25.TraversalSpec#setType() .
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: HostDatastoreSystemMO.java From cloudstack with Apache License 2.0 | 6 votes |
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); }
Example 2
Source File: DatacenterMO.java From cloudstack with Apache License 2.0 | 6 votes |
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); }
Example 3
Source File: ClusterMO.java From cloudstack with Apache License 2.0 | 5 votes |
@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()]); }
Example 4
Source File: VimUtil.java From vsphere-automation-sdk-java with MIT License | 5 votes |
/** * @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 5
Source File: ClusterMO.java From cloudstack with Apache License 2.0 | 5 votes |
@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()]); }
Example 6
Source File: ClusterMO.java From cloudstack with Apache License 2.0 | 5 votes |
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()]); }
Example 7
Source File: HostMO.java From cloudstack with Apache License 2.0 | 5 votes |
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; }
Example 8
Source File: HostMO.java From cloudstack with Apache License 2.0 | 5 votes |
@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()]); }
Example 9
Source File: HostMO.java From cloudstack with Apache License 2.0 | 5 votes |
@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()]); }
Example 10
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 5 votes |
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; }
Example 11
Source File: DatacenterMO.java From cloudstack with Apache License 2.0 | 5 votes |
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 12
Source File: DatacenterMO.java From cloudstack with Apache License 2.0 | 5 votes |
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 13
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 5 votes |
public List<DatastoreMO> getAllDatastores() throws Exception { 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); List<DatastoreMO> datastores = new ArrayList<DatastoreMO>(); if (CollectionUtils.isNotEmpty(ocs)) { for (ObjectContent oc : ocs) { datastores.add(new DatastoreMO(_context, oc.getObj())); } } return datastores; }
Example 14
Source File: DatacenterMO.java From cloudstack with Apache License 2.0 | 5 votes |
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; }
Example 15
Source File: DatastoreMO.java From cloudstack with Apache License 2.0 | 4 votes |
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 16
Source File: VirtualMachineMO.java From cloudstack with Apache License 2.0 | 4 votes |
public List<NetworkDetails> getNetworksWithDetails() throws Exception { List<NetworkDetails> networks = new ArrayList<NetworkDetails>(); int gcTagKey = getCustomFieldKey("Network", CustomFieldConstants.CLOUD_GC); if (gcTagKey == 0) { gcTagKey = getCustomFieldKey("DistributedVirtualPortgroup", CustomFieldConstants.CLOUD_GC_DVP); s_logger.debug("The custom key for dvPortGroup is : " + gcTagKey); } PropertySpec pSpec = new PropertySpec(); pSpec.setType("Network"); pSpec.getPathSet().add("name"); pSpec.getPathSet().add("vm"); pSpec.getPathSet().add(String.format("value[%d]", gcTagKey)); 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); if (ocs != null && ocs.size() > 0) { for (ObjectContent oc : ocs) { ArrayOfManagedObjectReference morVms = null; String gcTagValue = null; String name = null; for (DynamicProperty prop : oc.getPropSet()) { if (prop.getName().equals("name")) name = prop.getVal().toString(); else if (prop.getName().equals("vm")) morVms = (ArrayOfManagedObjectReference)prop.getVal(); else if (prop.getName().startsWith("value[")) { CustomFieldStringValue val = (CustomFieldStringValue)prop.getVal(); if (val != null) gcTagValue = val.getValue(); } } NetworkDetails details = new NetworkDetails(name, oc.getObj(), (morVms != null ? morVms.getManagedObjectReference().toArray( new ManagedObjectReference[morVms.getManagedObjectReference().size()]) : null), gcTagValue); networks.add(details); } s_logger.debug("Retrieved " + networks.size() + " networks with key : " + gcTagKey); } return networks; }
Example 17
Source File: DatacenterMO.java From cloudstack with Apache License 2.0 | 4 votes |
public DVPortgroupConfigInfo getDvPortGroupSpec(String dvPortGroupName) throws Exception { DVPortgroupConfigInfo configSpec = null; String nameProperty = null; PropertySpec pSpec = new PropertySpec(); pSpec.setType("DistributedVirtualPortgroup"); pSpec.getPathSet().add("name"); pSpec.getPathSet().add("config"); 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("config")) { configSpec = (DVPortgroupConfigInfo)prop.getVal(); } else { nameProperty = prop.getVal().toString(); } } if (nameProperty.equalsIgnoreCase(dvPortGroupName)) { return configSpec; } } } } return null; }
Example 18
Source File: VMwareUtil.java From cloudstack with Apache License 2.0 | 4 votes |
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; }
Example 19
Source File: ManagedObjectAccessor.java From development with Apache License 2.0 | 4 votes |
/** * Returns all the managed object references of the specified type that are * present under the container. * * @param folder * {@link ManagedObjectReference} of the container to begin the * search from * @param morefType * type of the managed entity that needs to be searched * * @return map of name and MoRef of the managed objects present. May be * empty but not <code>null</code> * * @throws InvalidPropertyFaultMsg * @throws RuntimeFaultFaultMsg */ public Map<String, ManagedObjectReference> getMoRefsInContainerByType( ManagedObjectReference folder, String morefType) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg { String PROP_ME_NAME = "name"; ManagedObjectReference viewManager = serviceContent.getViewManager(); ManagedObjectReference containerView = vimPort.createContainerView( viewManager, folder, Arrays.asList(morefType), true); Map<String, ManagedObjectReference> tgtMoref = new HashMap<String, ManagedObjectReference>(); PropertySpec propertySpec = new PropertySpec(); propertySpec.setAll(Boolean.FALSE); propertySpec.setType(morefType); propertySpec.getPathSet().add(PROP_ME_NAME); TraversalSpec ts = new TraversalSpec(); ts.setName("view"); ts.setPath("view"); ts.setSkip(Boolean.FALSE); ts.setType("ContainerView"); ObjectSpec objectSpec = new ObjectSpec(); objectSpec.setObj(containerView); objectSpec.setSkip(Boolean.TRUE); objectSpec.getSelectSet().add(ts); PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpec(); propertyFilterSpec.getPropSet().add(propertySpec); propertyFilterSpec.getObjectSet().add(objectSpec); List<PropertyFilterSpec> propertyFilterSpecs = new ArrayList<PropertyFilterSpec>(); propertyFilterSpecs.add(propertyFilterSpec); RetrieveResult rslts = vimPort.retrievePropertiesEx( serviceContent.getPropertyCollector(), propertyFilterSpecs, new RetrieveOptions()); List<ObjectContent> listobjcontent = new ArrayList<ObjectContent>(); if (rslts != null && rslts.getObjects() != null && !rslts.getObjects().isEmpty()) { listobjcontent.addAll(rslts.getObjects()); } String token = null; if (rslts != null && rslts.getToken() != null) { token = rslts.getToken(); } while (token != null && token.length() > 0) { rslts = vimPort.continueRetrievePropertiesEx( serviceContent.getPropertyCollector(), token); token = null; if (rslts != null) { token = rslts.getToken(); if (rslts.getObjects() != null && !rslts.getObjects().isEmpty()) { listobjcontent.addAll(rslts.getObjects()); } } } for (ObjectContent oc : listobjcontent) { ManagedObjectReference mr = oc.getObj(); String entityNm = null; List<DynamicProperty> dps = oc.getPropSet(); if (dps != null) { for (DynamicProperty dp : dps) { entityNm = (String) dp.getVal(); } } tgtMoref.put(entityNm, mr); } return tgtMoref; }
Example 20
Source File: VimUtil.java From vsphere-automation-sdk-java with MIT License | 4 votes |
/** * 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; }