From 12f2d804ebcaa62c790b1d9cd699b080320902d6 Mon Sep 17 00:00:00 2001 From: Abhisar Sinha <63767682+abh1sar@users.noreply.github.com> Date: Wed, 16 Jul 2025 14:03:18 +0530 Subject: [PATCH 1/5] Guard OS type update for iso/template with existing vms --- .../apache/cloudstack/api/ApiConstants.java | 1 + .../api/BaseUpdateTemplateOrIsoCmd.java | 8 ++++++++ .../cloud/template/TemplateManagerImpl.java | 6 ++++++ ui/public/locales/en.json | 1 + ui/src/views/image/UpdateISO.vue | 19 +++++++++++++++++-- ui/src/views/image/UpdateTemplate.vue | 18 +++++++++++++++++- 6 files changed, 50 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java index 22e7e8075020..9bbfe25df2af 100644 --- a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java +++ b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java @@ -220,6 +220,7 @@ public class ApiConstants { public static final String FORCED_DESTROY_LOCAL_STORAGE = "forcedestroylocalstorage"; public static final String FORCE_DELETE_HOST = "forcedeletehost"; public static final String FORCE_MS_TO_IMPORT_VM_FILES = "forcemstoimportvmfiles"; + public static final String FORCE_UPDATE_OS_TYPE = "forceupdateostype"; public static final String FORMAT = "format"; public static final String FOR_VIRTUAL_NETWORK = "forvirtualnetwork"; public static final String FOR_SYSTEM_VMS = "forsystemvms"; diff --git a/api/src/main/java/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoCmd.java index 9a8282df1121..5be61d83eed4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoCmd.java @@ -51,6 +51,10 @@ public abstract class BaseUpdateTemplateOrIsoCmd extends BaseCmd { description = "the ID of the OS type that best represents the OS of this image.") private Long osTypeId; + @Parameter(name = ApiConstants.FORCE_UPDATE_OS_TYPE, type = CommandType.BOOLEAN, description = "Force OS type update. Warning: Updating OS type will update the guest OS configuration" + + "for all the existing VMs deployed with this template/iso, which may affect their behavior.") + private Boolean forceUpdateOsType; + @Parameter(name = ApiConstants.FORMAT, type = CommandType.STRING, description = "the format for the image") private String format; @@ -112,6 +116,10 @@ public Long getOsTypeId() { return osTypeId; } + public Boolean getForceUpdateOsType() { + return forceUpdateOsType; + } + public Boolean getPasswordEnabled() { return passwordEnabled; } diff --git a/server/src/main/java/com/cloud/template/TemplateManagerImpl.java b/server/src/main/java/com/cloud/template/TemplateManagerImpl.java index 6759144837d5..672b3f009482 100755 --- a/server/src/main/java/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/main/java/com/cloud/template/TemplateManagerImpl.java @@ -2238,6 +2238,12 @@ private VMTemplateVO updateTemplateOrIso(BaseUpdateTemplateOrIsoCmd cmd) { sc.addAnd("state", SearchCriteria.Op.NEQ, State.Expunging); List vms = _vmInstanceDao.search(sc, null); if (vms != null && !vms.isEmpty()) { + if (!Boolean.TRUE.equals(cmd.getForceUpdateOsType())) { + String message = String.format("Updating OS type will update the guest OS configuration " + + "for all of the %d VM(s) deployed with this Template/ISO, which may affect their behavior. " + + "To proceed, please set the 'forceupdateostype' parameter to true.", vms.size()); + throw new InvalidParameterValueException(message); + } for (VMInstanceVO vm: vms) { vm.setGuestOSId(guestOSId); _vmInstanceDao.update(vm.getId(), vm); diff --git a/ui/public/locales/en.json b/ui/public/locales/en.json index b649f6914bb9..028d32eccc67 100644 --- a/ui/public/locales/en.json +++ b/ui/public/locales/en.json @@ -1038,6 +1038,7 @@ "label.forbidden": "Forbidden", "label.forced": "Force", "label.force.ms.to.import.vm.files": "Enable to force OVF Download via Management Server. Disable to use KVM Host ovftool (if installed)", +"label.force.update.os.type": "Force update OS type", "label.force.stop": "Force stop", "label.force.reboot": "Force reboot", "label.forceencap": "Force UDP encapsulation of ESP packets", diff --git a/ui/src/views/image/UpdateISO.vue b/ui/src/views/image/UpdateISO.vue index 856038f2d5f9..15d57458ff6a 100644 --- a/ui/src/views/image/UpdateISO.vue +++ b/ui/src/views/image/UpdateISO.vue @@ -67,6 +67,13 @@ + + + + +