Search in sources :

Example 1 with ResourcePool

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");
}
Also used : ServiceUtil(com.vmware.apputils.vim25.ServiceUtil) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 2 with 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;
}
Also used : TraversalSpec(com.vmware.vim25.TraversalSpec) SelectionSpec(com.vmware.vim25.SelectionSpec) ArrayList(java.util.ArrayList)

Example 3 with ResourcePool

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");
    }
}
Also used : ArrayList(java.util.ArrayList) ResourcePool(com.vmware.vim25.mo.ResourcePool) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException) VirtualMachine(com.vmware.vim25.mo.VirtualMachine)

Example 4 with ResourcePool

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);
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec) ArrayList(java.util.ArrayList)

Example 5 with ResourcePool

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);
    }
}
Also used : PowerState(com.vmware.photon.controller.model.resources.ComputeService.PowerState) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) QueryTask(com.vmware.xenon.services.common.QueryTask) ObjectUpdateKind(com.vmware.vim25.ObjectUpdateKind) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) VsphereEnumerationHelper.convertOnlyResultToDocument(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.convertOnlyResultToDocument) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) VimNames(com.vmware.photon.controller.model.adapters.vsphere.util.VimNames) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) List(java.util.List) UriUtils.buildUriPath(com.vmware.xenon.common.UriUtils.buildUriPath) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) VsphereEnumerationHelper.withTaskResults(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.withTaskResults) Collections(java.util.Collections) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) QueryTask(com.vmware.xenon.services.common.QueryTask) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException)

Aggregations

ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)8 TraversalSpec (com.vmware.vim25.TraversalSpec)6 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)5 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)5 GetMoRef (com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef)4 FinderException (com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException)4 MethodFault (com.vmware.vim25.MethodFault)4 TaskInfo (com.vmware.vim25.TaskInfo)4 VirtualMachineDefinedProfileSpec (com.vmware.vim25.VirtualMachineDefinedProfileSpec)4 VirtualMachineRelocateSpec (com.vmware.vim25.VirtualMachineRelocateSpec)4 ArrayList (java.util.ArrayList)4 Lock (java.util.concurrent.locks.Lock)4 ReentrantLock (java.util.concurrent.locks.ReentrantLock)4 ClientUtils.findMatchingVirtualDevice (com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findMatchingVirtualDevice)3 OvfDeployer (com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfDeployer)3 OvfParser (com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfParser)3 OvfRetriever (com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfRetriever)3 ArrayOfVirtualDevice (com.vmware.vim25.ArrayOfVirtualDevice)3 DuplicateName (com.vmware.vim25.DuplicateName)3 FileAlreadyExists (com.vmware.vim25.FileAlreadyExists)3