Skip to content

Commit 56b2ea1

Browse files
committed
server: prevent adding of compute details for vm when using fixed offering
cpuNumber, memory and cpuSpeed shouldn't be added for VMs which use fixed offerings. It creates confusion and when adding cpuSpeed as zero for constrained offering which uses limit CPU flag, VM can failed to boot if speed specified is zero or very low. Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 34f6f41 commit 56b2ea1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,8 +1305,9 @@ public void validateCustomParameters(ServiceOfferingVO serviceOffering, Map<Stri
13051305
throw new InvalidParameterValueException("Invalid CPU speed value, specify a value between 1 and " + Integer.MAX_VALUE);
13061306
}
13071307
} else if (!serviceOffering.isCustomCpuSpeedSupported() && customParameters.containsKey(UsageEventVO.DynamicParameters.cpuSpeed.name())) {
1308-
throw new InvalidParameterValueException("The CPU speed of this offering id:" + serviceOffering.getUuid()
1309-
+ " is not customizable. This is predefined in the Template.");
1308+
throw new InvalidParameterValueException(String.format("The CPU speed of this offering id:%s"
1309+
+ " is not customizable. This is predefined as %d MHz.",
1310+
serviceOffering.getUuid(), serviceOffering.getSpeed()));
13101311
}
13111312

13121313
if (serviceOffering.getRamSize() == null) {
@@ -2765,10 +2766,16 @@ protected void verifyVmLimits(UserVmVO vmInstance, Map<String, String> details)
27652766
Map<String, String> customParameters = new HashMap<>();
27662767
customParameters.put(VmDetailConstants.CPU_NUMBER, String.valueOf(newCpu));
27672768
customParameters.put(VmDetailConstants.MEMORY, String.valueOf(newMemory));
2768-
if (svcOffering.isCustomCpuSpeedSupported()) {
2769+
if (details.containsKey(VmDetailConstants.CPU_SPEED)) {
27692770
customParameters.put(VmDetailConstants.CPU_SPEED, details.get(VmDetailConstants.CPU_SPEED));
27702771
}
27712772
validateCustomParameters(svcOffering, customParameters);
2773+
} else {
2774+
if (details.containsKey(VmDetailConstants.CPU_NUMBER) || details.containsKey(VmDetailConstants.MEMORY) ||
2775+
details.containsKey(VmDetailConstants.CPU_SPEED)) {
2776+
throw new InvalidParameterValueException("CPU number, Memory and CPU speed cannot be updated for a " +
2777+
"non-dynamic offering");
2778+
}
27722779
}
27732780
if (VirtualMachineManager.ResourceCountRunningVMsonly.value()) {
27742781
return;

0 commit comments

Comments
 (0)