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);
}
Aggregations