This is an automated email from the ASF dual-hosted git repository.
weizhou pushed a commit to branch 4.18
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.18 by this push:
new 26581b77411 server: throw new exception when rootdisksize is required
but not set (#7913)
26581b77411 is described below
commit 26581b774116df48740d0511004201ad34993cf2
Author: Wei Zhou <[email protected]>
AuthorDate: Mon Aug 28 08:57:40 2023 +0200
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
---
.../cloudstack/api/command/user/vm/DeployVMCmd.java | 4 ++--
.../src/main/java/com/cloud/vm/UserVmManagerImpl.java | 17 ++++++++++-------
2 files changed, 12 insertions(+), 9 deletions(-)
diff --git
a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
index ef6dba63166..107bd817516 100644
---
a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
+++
b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
@@ -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();
diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
index c1840065603..c9085b385f5 100644
--- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
@@ -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 {