use of com.vmware.vim25.ObjectSpec in project photon-model by vmware.
the class EnumerationClient method createVmFilterSpec.
public PropertyFilterSpec createVmFilterSpec(ManagedObjectReference dc) {
ObjectSpec ospec = new ObjectSpec();
ospec.setObj(dc);
ospec.setSkip(false);
ospec.getSelectSet().addAll(buildFullTraversal());
PropertySpec vmSpec = new PropertySpec();
vmSpec.setType(VimNames.TYPE_VM);
vmSpec.getPathSet().addAll(Arrays.asList(VimPath.vm_config_name, VimPath.vm_config_instanceUuid, VimPath.vm_config_changeVersion, VimPath.vm_config_hardware_device, VimPath.vm_config_hardware_memoryMB, VimPath.vm_summary_config_numCpu, VimPath.vm_config_template, VimPath.vm_runtime_host, VimPath.vm_guest_net, VimPath.vm_guest_hostName, VimPath.vm_runtime_powerState, VimPath.vm_runtime_maxCpuUsage, VimPath.vm_runtime_maxMemoryUsage, VimPath.vm_summary_guest_ipAddress, VimPath.vm_summary_guest_hostName, VimPath.vm_snapshot_rootSnapshotList, VimPath.res_resourcePool, VimPath.vm_summary_config_guestFullName));
PropertyFilterSpec filterSpec = new PropertyFilterSpec();
filterSpec.getObjectSet().add(ospec);
filterSpec.getPropSet().add(vmSpec);
return filterSpec;
}
use of com.vmware.vim25.ObjectSpec in project cloudstack by apache.
the class VirtualMachineMO method getAllDatastores.
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;
}
use of com.vmware.vim25.ObjectSpec in project cloudstack by apache.
the class VirtualMachineMO method getNetworks.
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]);
}
use of com.vmware.vim25.ObjectSpec in project cloudstack by apache.
the class HostMO method getVmPropertiesOnHyperHost.
@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()]);
}
use of com.vmware.vim25.ObjectSpec in project cloudstack by apache.
the class HostMO method getNetworkMor.
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;
}
Aggregations