server: throw new exception when rootdisksize is required but not set (#7913)

* server: throw new exception when rootdisksize is required but not set

* PR7913: fix an issue with PR6441
This commit is contained in:
Wei Zhou 2023-08-28 08:57:40 +02:00 committed by GitHub
parent 0dd6bb7c67
commit 26581b7741
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 9 deletions

View File

@ -315,8 +315,8 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityG
customparameterMap.put(getBootType().toString(), getBootMode().toString());
}
if (rootdisksize != null && !customparameterMap.containsKey("rootdisksize")) {
customparameterMap.put("rootdisksize", rootdisksize.toString());
if (rootdisksize != null && !customparameterMap.containsKey(VmDetailConstants.ROOT_DISK_SIZE)) {
customparameterMap.put(VmDetailConstants.ROOT_DISK_SIZE, rootdisksize.toString());
}
IoDriverPolicy ioPolicy = getIoDriverPolicy();

View File

@ -3933,7 +3933,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
rootDiskOfferingId = diskOfferingId;
diskOfferingId = null;
}
if (!customParameters.containsKey(VmDetailConstants.ROOT_DISK_SIZE)) {
if (!customParameters.containsKey(VmDetailConstants.ROOT_DISK_SIZE) && diskSize != null) {
customParameters.put(VmDetailConstants.ROOT_DISK_SIZE, String.valueOf(diskSize));
}
}
@ -4320,7 +4320,14 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
*/
protected long configureCustomRootDiskSize(Map<String, String> customParameters, VMTemplateVO template, HypervisorType hypervisorType, DiskOfferingVO rootDiskOffering) {
verifyIfHypervisorSupportsRootdiskSizeOverride(hypervisorType);
long rootDiskSizeInBytes = verifyAndGetDiskSize(rootDiskOffering, NumbersUtil.parseLong(customParameters.get(VmDetailConstants.ROOT_DISK_SIZE), -1));
Long rootDiskSizeCustomParam = null;
if (customParameters.containsKey(VmDetailConstants.ROOT_DISK_SIZE)) {
rootDiskSizeCustomParam = NumbersUtil.parseLong(customParameters.get(VmDetailConstants.ROOT_DISK_SIZE), -1);
if (rootDiskSizeCustomParam <= 0) {
throw new InvalidParameterValueException("Root disk size should be a positive number.");
}
}
long rootDiskSizeInBytes = verifyAndGetDiskSize(rootDiskOffering, rootDiskSizeCustomParam);
if (rootDiskSizeInBytes > 0) { //if the size at DiskOffering is not zero then the Service Offering had it configured, it holds priority over the User custom size
_volumeService.validateVolumeSizeInBytes(rootDiskSizeInBytes);
long rootDiskSizeInGiB = rootDiskSizeInBytes / GiB_TO_BYTES;
@ -4329,11 +4336,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
}
if (customParameters.containsKey(VmDetailConstants.ROOT_DISK_SIZE)) {
Long rootDiskSize = NumbersUtil.parseLong(customParameters.get(VmDetailConstants.ROOT_DISK_SIZE), -1);
if (rootDiskSize <= 0) {
throw new InvalidParameterValueException("Root disk size should be a positive number.");
}
rootDiskSize *= GiB_TO_BYTES;
Long rootDiskSize = rootDiskSizeCustomParam * GiB_TO_BYTES;
_volumeService.validateVolumeSizeInBytes(rootDiskSize);
return rootDiskSize;
} else {