Search in sources :

Example 1 with ComplianceStatus

use of com.cloud.model.enumeration.ComplianceStatus in project cosmic by MissionCriticalCloud.

the class UserVmManagerImpl method updateVirtualMachine.

@Override
@ActionEvent(eventType = EventTypes.EVENT_VM_UPDATE, eventDescription = "updating Vm")
public UserVm updateVirtualMachine(final UpdateVMCmd cmd) throws ResourceUnavailableException, InsufficientCapacityException {
    final String displayName = cmd.getDisplayName();
    final String group = cmd.getGroup();
    final Boolean ha = cmd.getHaEnable();
    final Boolean isDisplayVm = cmd.getDisplayVm();
    final Long id = cmd.getId();
    final Long osTypeId = cmd.getOsTypeId();
    final String userData = cmd.getUserData();
    final Boolean isDynamicallyScalable = cmd.isDynamicallyScalable();
    final String hostName = cmd.getHostName();
    final Map<String, String> details = cmd.getDetails();
    final Account caller = CallContext.current().getCallingAccount();
    final OptimiseFor optimiseFor = cmd.getOptimiseFor();
    final String manufacturerString = cmd.getManufacturerString();
    final Boolean requiresRestart = cmd.getRequiresRestart();
    final MaintenancePolicy maintenancePolicy = cmd.getMaintenancePolicy();
    final Long bootMenuTimeout = cmd.getBootMenuTimeout();
    final String bootOrder = cmd.getBootOrder();
    final ComplianceStatus complianceStatus = cmd.getComplianceStatus();
    // Input validation and permission checks
    final UserVmVO vmInstance = _vmDao.findById(id);
    if (vmInstance == null) {
        throw new InvalidParameterValueException("unable to find virtual machine with id " + id);
    }
    _accountMgr.checkAccess(caller, null, true, vmInstance);
    // If the flag is specified and is changed
    if (isDisplayVm != null && isDisplayVm != vmInstance.isDisplayVm()) {
        // update vm
        vmInstance.setDisplayVm(isDisplayVm);
        // Resource limit changes
        final ServiceOffering offering = _serviceOfferingDao.findByIdIncludingRemoved(vmInstance.getServiceOfferingId());
        _resourceLimitMgr.changeResourceCount(vmInstance.getAccountId(), ResourceType.user_vm, isDisplayVm);
        _resourceLimitMgr.changeResourceCount(vmInstance.getAccountId(), ResourceType.cpu, isDisplayVm, new Long(offering.getCpu()));
        _resourceLimitMgr.changeResourceCount(vmInstance.getAccountId(), ResourceType.memory, isDisplayVm, new Long(offering.getRamSize()));
        // take care of the root volume as well.
        final List<VolumeVO> rootVols = _volsDao.findByInstanceAndType(id, VolumeType.ROOT);
        if (!rootVols.isEmpty()) {
            _volumeService.updateDisplay(rootVols.get(0), isDisplayVm);
        }
        // take care of the data volumes as well.
        final List<VolumeVO> dataVols = _volsDao.findByInstanceAndType(id, VolumeType.DATADISK);
        for (final Volume dataVol : dataVols) {
            _volumeService.updateDisplay(dataVol, isDisplayVm);
        }
    }
    if (details != null && !details.isEmpty()) {
        _vmDao.loadDetails(vmInstance);
        for (final Map.Entry<String, String> entry : details.entrySet()) {
            if (entry instanceof Map.Entry) {
                vmInstance.setDetail(entry.getKey(), entry.getValue());
            }
        }
        _vmDao.saveDetails(vmInstance);
    }
    return updateVirtualMachine(id, displayName, group, ha, isDisplayVm, osTypeId, userData, isDynamicallyScalable, cmd.getHttpMethod(), cmd.getCustomId(), hostName, cmd.getInstanceName(), manufacturerString, optimiseFor, requiresRestart, maintenancePolicy, bootMenuTimeout, bootOrder, complianceStatus);
}
Also used : Account(com.cloud.legacymodel.user.Account) ComplianceStatus(com.cloud.model.enumeration.ComplianceStatus) ServiceOffering(com.cloud.offering.ServiceOffering) OptimiseFor(com.cloud.model.enumeration.OptimiseFor) Entry(java.util.Map.Entry) VmDiskStatsEntry(com.cloud.legacymodel.storage.VmDiskStatsEntry) VmStatsEntry(com.cloud.legacymodel.vm.VmStatsEntry) VolumeVO(com.cloud.storage.VolumeVO) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) Volume(com.cloud.legacymodel.storage.Volume) MaintenancePolicy(com.cloud.model.enumeration.MaintenancePolicy) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ActionEvent(com.cloud.event.ActionEvent)

Aggregations

ActionEvent (com.cloud.event.ActionEvent)1 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)1 VmDiskStatsEntry (com.cloud.legacymodel.storage.VmDiskStatsEntry)1 Volume (com.cloud.legacymodel.storage.Volume)1 Account (com.cloud.legacymodel.user.Account)1 VmStatsEntry (com.cloud.legacymodel.vm.VmStatsEntry)1 ComplianceStatus (com.cloud.model.enumeration.ComplianceStatus)1 MaintenancePolicy (com.cloud.model.enumeration.MaintenancePolicy)1 OptimiseFor (com.cloud.model.enumeration.OptimiseFor)1 ServiceOffering (com.cloud.offering.ServiceOffering)1 VolumeVO (com.cloud.storage.VolumeVO)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1