use of com.vmware.vim25.mo.ResourcePool in project CloudStack-archive by CloudStack-extras.
the class HostMO method getHyperHostOwnerResourcePool.
@Override
public ManagedObjectReference getHyperHostOwnerResourcePool() throws Exception {
ServiceUtil serviceUtil = _context.getServiceUtil();
ManagedObjectReference morComputerResource = (ManagedObjectReference) serviceUtil.getDynamicProperty(_mor, "parent");
return (ManagedObjectReference) serviceUtil.getDynamicProperty(morComputerResource, "resourcePool");
}
use of com.vmware.vim25.mo.ResourcePool in project cloudstack by apache.
the class VmwareClient method constructCompleteTraversalSpec.
/*
* @return An array of SelectionSpec covering VM, Host, Resource pool,
* Cluster Compute Resource and Datastore.
*/
private List<SelectionSpec> constructCompleteTraversalSpec() {
// ResourcePools to VM: RP -> VM
TraversalSpec rpToVm = new TraversalSpec();
rpToVm.setName("rpToVm");
rpToVm.setType("ResourcePool");
rpToVm.setPath("vm");
rpToVm.setSkip(Boolean.FALSE);
// VirtualApp to VM: vApp -> VM
TraversalSpec vAppToVM = new TraversalSpec();
vAppToVM.setName("vAppToVM");
vAppToVM.setType("VirtualApp");
vAppToVM.setPath("vm");
// Host to VM: HostSystem -> VM
TraversalSpec hToVm = new TraversalSpec();
hToVm.setType("HostSystem");
hToVm.setPath("vm");
hToVm.setName("hToVm");
hToVm.getSelectSet().add(getSelectionSpec("VisitFolders"));
hToVm.setSkip(Boolean.FALSE);
// DataCenter to DataStore: DC -> DS
TraversalSpec dcToDs = new TraversalSpec();
dcToDs.setType("Datacenter");
dcToDs.setPath("datastore");
dcToDs.setName("dcToDs");
dcToDs.setSkip(Boolean.FALSE);
// Recurse through all ResourcePools
TraversalSpec rpToRp = new TraversalSpec();
rpToRp.setType("ResourcePool");
rpToRp.setPath("resourcePool");
rpToRp.setSkip(Boolean.FALSE);
rpToRp.setName("rpToRp");
rpToRp.getSelectSet().add(getSelectionSpec("rpToRp"));
TraversalSpec crToRp = new TraversalSpec();
crToRp.setType("ComputeResource");
crToRp.setPath("resourcePool");
crToRp.setSkip(Boolean.FALSE);
crToRp.setName("crToRp");
crToRp.getSelectSet().add(getSelectionSpec("rpToRp"));
TraversalSpec crToH = new TraversalSpec();
crToH.setSkip(Boolean.FALSE);
crToH.setType("ComputeResource");
crToH.setPath("host");
crToH.setName("crToH");
TraversalSpec dcToHf = new TraversalSpec();
dcToHf.setSkip(Boolean.FALSE);
dcToHf.setType("Datacenter");
dcToHf.setPath("hostFolder");
dcToHf.setName("dcToHf");
dcToHf.getSelectSet().add(getSelectionSpec("VisitFolders"));
TraversalSpec vAppToRp = new TraversalSpec();
vAppToRp.setName("vAppToRp");
vAppToRp.setType("VirtualApp");
vAppToRp.setPath("resourcePool");
vAppToRp.getSelectSet().add(getSelectionSpec("rpToRp"));
TraversalSpec dcToVmf = new TraversalSpec();
dcToVmf.setType("Datacenter");
dcToVmf.setSkip(Boolean.FALSE);
dcToVmf.setPath("vmFolder");
dcToVmf.setName("dcToVmf");
dcToVmf.getSelectSet().add(getSelectionSpec("VisitFolders"));
// For Folder -> Folder recursion
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(getSelectionSpec("crToRp"));
sspecarrvf.add(getSelectionSpec("crToH"));
sspecarrvf.add(getSelectionSpec("dcToVmf"));
sspecarrvf.add(getSelectionSpec("dcToHf"));
sspecarrvf.add(getSelectionSpec("vAppToRp"));
sspecarrvf.add(getSelectionSpec("vAppToVM"));
sspecarrvf.add(getSelectionSpec("dcToDs"));
sspecarrvf.add(getSelectionSpec("hToVm"));
sspecarrvf.add(getSelectionSpec("rpToVm"));
sspecarrvf.add(getSelectionSpec("VisitFolders"));
visitFolders.getSelectSet().addAll(sspecarrvf);
List<SelectionSpec> resultspec = new ArrayList<SelectionSpec>();
resultspec.add(visitFolders);
resultspec.add(crToRp);
resultspec.add(crToH);
resultspec.add(dcToVmf);
resultspec.add(dcToHf);
resultspec.add(vAppToRp);
resultspec.add(vAppToVM);
resultspec.add(dcToDs);
resultspec.add(hToVm);
resultspec.add(rpToVm);
resultspec.add(rpToRp);
return resultspec;
}
use of com.vmware.vim25.mo.ResourcePool in project coprhd-controller by CoprHD.
the class VcenterApiClient method getVirtualMachines.
private List<VirtualMachine> getVirtualMachines(ClusterComputeResource clusterComputeResource, boolean runningOnly) throws VcenterSystemException {
try {
List<VirtualMachine> virtualMachines = new ArrayList<VirtualMachine>();
String clusterName = clusterComputeResource.getName();
_log.info("Inspect cluster " + clusterName + " for virtual machines running only " + runningOnly);
ResourcePool resourcePool = clusterComputeResource.getResourcePool();
if (resourcePool != null) {
_log.info("Inspect resource pool " + resourcePool.getName() + " for virtual machines");
if (resourcePool.getVMs() != null) {
for (VirtualMachine virtualMachine : resourcePool.getVMs()) {
_log.info("Found virtual machine " + virtualMachine.getName() + " in resource pool " + resourcePool.getName());
_log.info(toDetails(virtualMachine));
if (runningOnly) {
// Anything !poweredOff (poweredOn and suspended) will be considered running
if (!virtualMachine.getRuntime().getPowerState().equals(VirtualMachinePowerState.poweredOff)) {
virtualMachines.add(virtualMachine);
}
} else {
virtualMachines.add(virtualMachine);
}
}
}
}
_log.info("Cluster " + clusterName + " has " + virtualMachines.size() + " virtual machines");
return virtualMachines;
} catch (Exception e) {
_log.error("getVirtualMachines clusterComputeResource exception " + e);
throw new VcenterSystemException("Error checking cluster for virtual machines");
}
}
use of com.vmware.vim25.mo.ResourcePool in project photon-model by vmware.
the class Lister method listResourcePool.
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);
}
use of com.vmware.vim25.mo.ResourcePool in project photon-model by vmware.
the class VSphereResourcePoolEnumerationHelper method handleResourcePoolChanges.
public static void handleResourcePoolChanges(VSphereIncrementalEnumerationService service, List<ResourcePoolOverlay> resourcePools, EnumerationProgress enumerationProgress, EnumerationClient client) {
ComputeEnumerateResourceRequest request = enumerationProgress.getRequest();
enumerationProgress.expectResourcePoolCount(resourcePools.size());
for (ResourcePoolOverlay resourcePool : resourcePools) {
// no need to collect the root resource pool
if (ObjectUpdateKind.ENTER.equals(resourcePool.getObjectUpdateKind()) && VimNames.TYPE_RESOURCE_POOL.equals(resourcePool.getParent().getType())) {
String ownerMoRefId = resourcePool.getOwner().getValue();
QueryTask task = queryForRPOwner(ownerMoRefId, enumerationProgress);
String selfLink = buildStableResourcePoolLink(resourcePool.getId(), request.endpointLink);
withTaskResults(service, task, result -> {
try {
if (!result.documentLinks.isEmpty()) {
ComputeState ownerDocument = convertOnlyResultToDocument(result, ComputeState.class);
createNewResourcePool(service, enumerationProgress, ownerDocument.name, selfLink, resourcePool, client);
} else {
// This happens for the resource pools within Host. The owner is a ComputeResource and
// is not currently enumerated in photon
createNewResourcePool(service, enumerationProgress, null, selfLink, resourcePool, client);
}
} catch (Exception e) {
enumerationProgress.getResourcePoolTracker().track();
}
});
} else {
String rpSelfLink = buildStableResourcePoolLink(resourcePool.getId(), request.endpointLink);
Operation.createGet(PhotonModelUriUtils.createInventoryUri(service.getHost(), rpSelfLink)).setCompletion((o, e) -> {
try {
if (e == null) {
ComputeState oldState = o.getBody(ComputeState.class);
String existingOwnerName = getOwnerNameFromResourcePoolName(oldState.name);
if (ObjectUpdateKind.MODIFY.equals(resourcePool.getObjectUpdateKind())) {
updateResourcePool(service, enumerationProgress, existingOwnerName, oldState.documentSelfLink, resourcePool, false, client);
} else {
Operation.createDelete(PhotonModelUriUtils.createInventoryUri(service.getHost(), rpSelfLink)).setCompletion(trackResourcePool(enumerationProgress, resourcePool)).sendWith(service);
}
} else {
enumerationProgress.getResourcePoolTracker().track();
}
} catch (Exception ex) {
enumerationProgress.getResourcePoolTracker().track();
}
}).sendWith(service);
}
}
try {
enumerationProgress.getResourcePoolTracker().await();
} catch (InterruptedException e) {
service.logSevere("Interrupted during incremental enumeration for resource pools!", e);
}
}
Aggregations