From d681dfae781589c98b66f95b1236953bad54cf85 Mon Sep 17 00:00:00 2001 From: Daan Hoogland Date: Tue, 23 Dec 2025 14:18:12 +0100 Subject: [PATCH] constrained offerings should not have cpu speed of 0 --- .../ConfigurationManagerImpl.java | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java index 246681f75851..66aabdeff63c 100644 --- a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java @@ -3198,14 +3198,8 @@ public ServiceOffering createServiceOffering(final CreateServiceOfferingCmd cmd) final String offeringName = cmd.getServiceOfferingName(); final String name = cmd.getServiceOfferingName(); - if (name == null || name.length() == 0) { - throw new InvalidParameterValueException("Failed to create service offering: specify the name that has non-zero length"); - } - final String displayText = cmd.getDisplayText(); - if (displayText == null || displayText.length() == 0) { - throw new InvalidParameterValueException("Failed to create service offering " + name + ": specify the display text that has non-zero length"); - } + checkNameAndText(name, displayText); final Integer cpuNumber = cmd.getCpuNumber(); final Integer cpuSpeed = cmd.getCpuSpeed(); @@ -3217,6 +3211,8 @@ public ServiceOffering createServiceOffering(final CreateServiceOfferingCmd cmd) Integer maxMemory = cmd.getMaxMemory(); Integer minMemory = cmd.getMinMemory(); + checkSpeedOnConstrainedOffering(cmd.isCustomized(), cpuSpeed, offeringName, maxCPU, minCPU, maxMemory, minMemory); + // Check if service offering is Custom, // If Customized, the following conditions must hold // 1. cpuNumber, cpuSpeed and memory should be all null @@ -3382,6 +3378,28 @@ public ServiceOffering createServiceOffering(final CreateServiceOfferingCmd cmd) cmd.getDiskOfferingStrictness(), cmd.isCustomized(), cmd.getEncryptRoot(), cmd.isPurgeResources()); } + private static void checkNameAndText(String name, String displayText) { + if (name == null || name.length() == 0) { + throw new InvalidParameterValueException("Failed to create service offering: specify the name that has non-zero length"); + } + + if (displayText == null || displayText.length() == 0) { + throw new InvalidParameterValueException("Failed to create service offering " + name + ": specify the display text that has non-zero length"); + } + } + + private static void checkSpeedOnConstrainedOffering(boolean customised, Integer cpuSpeed, String offeringName, Integer maxCPU, Integer minCPU, Integer maxMemory, Integer minMemory) { + // Check for the combination of zero speed and custom or constrained offering + if (cpuSpeed != null && cpuSpeed.intValue() == 0) { + if (customised) { + throw new InvalidParameterValueException("Failed to create service offering " + offeringName + ": cpu speed cannot be zero for custom offerings"); + } + if (maxCPU != null || minCPU != null || maxMemory != null || minMemory != null) { + throw new InvalidParameterValueException("Failed to create service offering " + offeringName + ": cpu speed cannot be zero for constrained offerings"); + } + } + } + protected ServiceOfferingVO createServiceOffering(final long userId, final boolean isSystem, final VirtualMachine.Type vmType, final String name, final Integer cpu, final Integer ramSize, final Integer speed, final String displayText, final String provisioningType, final boolean localStorageRequired, final boolean offerHA, final boolean limitResourceUse, final boolean volatileVm, String tags, final List domainIds, List zoneIds, final String hostTag,