DaanHoogland commented on code in PR #8800: URL: https://github.com/apache/cloudstack/pull/8800#discussion_r1544657504
########## server/src/main/java/com/cloud/vm/UserVmManagerImpl.java: ########## @@ -7642,27 +7644,52 @@ public UserVm restoreVM(RestoreVMCmd cmd) throws InsufficientCapacityException, long vmId = cmd.getVmId(); Long newTemplateId = cmd.getTemplateId(); + Long rootDiskOfferingId = cmd.getRootDiskOfferingId(); + Long rootDiskSize = cmd.getRootDiskSize(); + boolean expunge = cmd.getExpungeRootDisk(); + + if (rootDiskSize != null && rootDiskSize < 0) { + throw new InvalidParameterValueException("Invalid disk size " + rootDiskSize); + } UserVmVO vm = _vmDao.findById(vmId); if (vm == null) { InvalidParameterValueException ex = new InvalidParameterValueException("Cannot find VM with ID " + vmId); ex.addProxyObject(String.valueOf(vmId), "vmId"); throw ex; } - _accountMgr.checkAccess(caller, null, true, vm); + DiskOffering diskOffering; + if (rootDiskOfferingId != null) { + diskOffering = _diskOfferingDao.findById(rootDiskOfferingId); + if (diskOffering == null) { + throw new InvalidParameterValueException("Cannot find disk offering with ID " + rootDiskOfferingId); + } + DataCenterVO zone = dataCenterDao.findById(vm.getDataCenterId()); + _accountMgr.checkAccess(caller, diskOffering, zone); + ServiceOfferingVO serviceOffering = serviceOfferingDao.findById(vm.getServiceOfferingId()); + if (serviceOffering.getDiskOfferingStrictness() && !serviceOffering.getDiskOfferingId().equals(rootDiskOfferingId)) { + throw new InvalidParameterValueException("VM's service offering has a strict disk offering requirement, and the specified disk offering does not match"); + } + } Review Comment: can this go in a new method? ########## server/src/main/java/com/cloud/vm/UserVmManagerImpl.java: ########## @@ -7797,15 +7826,22 @@ public Pair<UserVmVO, Volume> doInTransaction(final TransactionStatus status) th } else { newVol = volumeMgr.allocateDuplicateVolume(root, null); } - newVols.add(newVol); + + VolumeVO resizedVolume = (VolumeVO) newVol; if (userVmDetailsDao.findDetail(userVm.getId(), VmDetailConstants.ROOT_DISK_SIZE) == null && !newVol.getSize().equals(template.getSize())) { - VolumeVO resizedVolume = (VolumeVO) newVol; if (template.getSize() != null) { resizedVolume.setSize(template.getSize()); - _volsDao.update(resizedVolume.getId(), resizedVolume); } } + if (diskOffering != null) { + resizedVolume.setDiskOfferingId(diskOffering.getId()); + resizedVolume.setSize(diskOffering.getDiskSize()); + } + if (rootDiskSize != null) { + resizedVolume.setSize(rootDiskSize); + } + _volsDao.update(resizedVolume.getId(), resizedVolume); Review Comment: can these bits go in new methods? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@cloudstack.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org