Skip to content

Commit 26581b7

Browse files
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
1 parent 0dd6bb7 commit 26581b7

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ public Map<String, String> getDetails() {
315315
customparameterMap.put(getBootType().toString(), getBootMode().toString());
316316
}
317317

318-
if (rootdisksize != null && !customparameterMap.containsKey("rootdisksize")) {
319-
customparameterMap.put("rootdisksize", rootdisksize.toString());
318+
if (rootdisksize != null && !customparameterMap.containsKey(VmDetailConstants.ROOT_DISK_SIZE)) {
319+
customparameterMap.put(VmDetailConstants.ROOT_DISK_SIZE, rootdisksize.toString());
320320
}
321321

322322
IoDriverPolicy ioPolicy = getIoDriverPolicy();

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3933,7 +3933,7 @@ private UserVm createVirtualMachine(DataCenter zone, ServiceOffering serviceOffe
39333933
rootDiskOfferingId = diskOfferingId;
39343934
diskOfferingId = null;
39353935
}
3936-
if (!customParameters.containsKey(VmDetailConstants.ROOT_DISK_SIZE)) {
3936+
if (!customParameters.containsKey(VmDetailConstants.ROOT_DISK_SIZE) && diskSize != null) {
39373937
customParameters.put(VmDetailConstants.ROOT_DISK_SIZE, String.valueOf(diskSize));
39383938
}
39393939
}
@@ -4320,7 +4320,14 @@ public boolean checkIfDynamicScalingCanBeEnabled(VirtualMachine vm, ServiceOffer
43204320
*/
43214321
protected long configureCustomRootDiskSize(Map<String, String> customParameters, VMTemplateVO template, HypervisorType hypervisorType, DiskOfferingVO rootDiskOffering) {
43224322
verifyIfHypervisorSupportsRootdiskSizeOverride(hypervisorType);
4323-
long rootDiskSizeInBytes = verifyAndGetDiskSize(rootDiskOffering, NumbersUtil.parseLong(customParameters.get(VmDetailConstants.ROOT_DISK_SIZE), -1));
4323+
Long rootDiskSizeCustomParam = null;
4324+
if (customParameters.containsKey(VmDetailConstants.ROOT_DISK_SIZE)) {
4325+
rootDiskSizeCustomParam = NumbersUtil.parseLong(customParameters.get(VmDetailConstants.ROOT_DISK_SIZE), -1);
4326+
if (rootDiskSizeCustomParam <= 0) {
4327+
throw new InvalidParameterValueException("Root disk size should be a positive number.");
4328+
}
4329+
}
4330+
long rootDiskSizeInBytes = verifyAndGetDiskSize(rootDiskOffering, rootDiskSizeCustomParam);
43244331
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
43254332
_volumeService.validateVolumeSizeInBytes(rootDiskSizeInBytes);
43264333
long rootDiskSizeInGiB = rootDiskSizeInBytes / GiB_TO_BYTES;
@@ -4329,11 +4336,7 @@ protected long configureCustomRootDiskSize(Map<String, String> customParameters,
43294336
}
43304337

43314338
if (customParameters.containsKey(VmDetailConstants.ROOT_DISK_SIZE)) {
4332-
Long rootDiskSize = NumbersUtil.parseLong(customParameters.get(VmDetailConstants.ROOT_DISK_SIZE), -1);
4333-
if (rootDiskSize <= 0) {
4334-
throw new InvalidParameterValueException("Root disk size should be a positive number.");
4335-
}
4336-
rootDiskSize *= GiB_TO_BYTES;
4339+
Long rootDiskSize = rootDiskSizeCustomParam * GiB_TO_BYTES;
43374340
_volumeService.validateVolumeSizeInBytes(rootDiskSize);
43384341
return rootDiskSize;
43394342
} else {

0 commit comments

Comments
 (0)