use of com.vmware.vim25.TraversalSpec in project cloudstack by apache.
the class VirtualMachineMO method getOwnerDatastore.
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;
}
use of com.vmware.vim25.TraversalSpec in project cloudstack by apache.
the class VirtualMachineMO method getNetworksWithDetails.
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;
}
use of com.vmware.vim25.TraversalSpec in project cloudstack by apache.
the class DatacenterMO method getVmPropertiesOnDatacenterVmFolder.
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);
}
use of com.vmware.vim25.TraversalSpec in project cloudstack by apache.
the class DatacenterMO method getOwnerDatacenter.
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);
}
use of com.vmware.vim25.TraversalSpec in project cloudstack by apache.
the class DatacenterMO method getHostPropertiesOnDatacenterHostFolder.
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);
}
Aggregations