From 78716fb15c09e41fc179f87b41beabcb7a332d7d Mon Sep 17 00:00:00 2001 From: Daan Hoogland Date: Mon, 20 Apr 2026 10:22:50 +0200 Subject: [PATCH 1/3] merge conflict fixes --- .../com/cloud/vm/snapshot/VMSnapshotManagerImpl.java | 7 +++++++ .../apache/cloudstack/vm/UnmanagedVMsManagerImpl.java | 10 ++-------- .../cloudstack/vm/UnmanagedVMsManagerImplTest.java | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java b/server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java index bfec3247a7b8..baa74128ce38 100644 --- a/server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java +++ b/server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java @@ -764,6 +764,13 @@ public UserVm revertToSnapshot(Long vmSnapshotId) throws InsufficientCapacityExc "In order to revert to a Snapshot without memory you need to first stop the Instance."); } + if (userVm.getState() == VirtualMachine.State.Running && vmSnapshotVo.getType() == VMSnapshot.Type.Disk) { + throw new InvalidParameterValueException( + "Reverting to the Instance Snapshot is not allowed for running Instances as this would result in an Instance state change. " + + "For running Instances only Snapshots with memory can be reverted. " + + "In order to revert to a Snapshot without memory you need to first stop the Instance."); + } + if (userVm.getState() == VirtualMachine.State.Stopped && vmSnapshotVo.getType() == VMSnapshot.Type.DiskAndMemory) { throw new InvalidParameterValueException( "Reverting to the Instance Snapshot is not allowed for stopped Instances when the Snapshot contains memory as this would result in an Instance state change. " + diff --git a/server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java b/server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java index 56998325ba78..846eab599fd1 100644 --- a/server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java +++ b/server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java @@ -1325,10 +1325,7 @@ private UserVmResponse baseImportInstance(ImportUnmanagedInstanceCmd cmd) { List managedVms = new ArrayList<>(additionalNameFilters); managedVms.addAll(getHostsManagedVms(hosts)); - List resourceLimitHostTags = resourceLimitService.getResourceLimitHostTags(serviceOffering, template); - try (CheckedReservation vmReservation = new CheckedReservation(owner, Resource.ResourceType.user_vm, resourceLimitHostTags, 1L, reservationDao, resourceLimitService); - CheckedReservation cpuReservation = new CheckedReservation(owner, Resource.ResourceType.cpu, resourceLimitHostTags, Long.valueOf(serviceOffering.getCpu()), reservationDao, resourceLimitService); - CheckedReservation memReservation = new CheckedReservation(owner, Resource.ResourceType.memory, resourceLimitHostTags, Long.valueOf(serviceOffering.getRamSize()), reservationDao, resourceLimitService)) { + try { ActionEventUtils.onStartedActionEvent(userId, owner.getId(), EventTypes.EVENT_VM_IMPORT, cmd.getEventDescription(), null, null, true, 0); @@ -2673,10 +2670,7 @@ private UserVmResponse importKvmInstance(ImportVmCmd cmd) { UserVm userVm = null; - List resourceLimitHostTags = resourceLimitService.getResourceLimitHostTags(serviceOffering, template); - try (CheckedReservation vmReservation = new CheckedReservation(owner, Resource.ResourceType.user_vm, resourceLimitHostTags, 1L, reservationDao, resourceLimitService); - CheckedReservation cpuReservation = new CheckedReservation(owner, Resource.ResourceType.cpu, resourceLimitHostTags, Long.valueOf(serviceOffering.getCpu()), reservationDao, resourceLimitService); - CheckedReservation memReservation = new CheckedReservation(owner, Resource.ResourceType.memory, resourceLimitHostTags, Long.valueOf(serviceOffering.getRamSize()), reservationDao, resourceLimitService)) { + try { if (ImportSource.EXTERNAL == importSource) { String username = cmd.getUsername(); diff --git a/server/src/test/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImplTest.java b/server/src/test/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImplTest.java index 9655b797ae96..dad5ffe6f123 100644 --- a/server/src/test/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImplTest.java +++ b/server/src/test/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImplTest.java @@ -57,6 +57,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; +import org.apache.cloudstack.reservation.dao.ReservationDao; import org.apache.cloudstack.resourcelimit.Reserver; import org.apache.cloudstack.storage.datastore.db.ImageStoreDao; import org.apache.cloudstack.storage.datastore.db.ImageStoreVO; @@ -260,7 +261,6 @@ public class UnmanagedVMsManagerImplTest { ImportVMTaskVO importVMTaskVO; @Mock private VMInstanceDetailsDao vmInstanceDetailsDao; - @Mock private ConfigKey configKeyMockParamsAllowed; @Mock From 3821319b59e905cf1b828116d3dcad671a006ae4 Mon Sep 17 00:00:00 2001 From: dahn Date: Mon, 20 Apr 2026 10:56:52 +0200 Subject: [PATCH 2/3] Update server/src/test/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImplTest.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../org/apache/cloudstack/vm/UnmanagedVMsManagerImplTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/server/src/test/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImplTest.java b/server/src/test/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImplTest.java index dad5ffe6f123..874bce0f95ef 100644 --- a/server/src/test/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImplTest.java +++ b/server/src/test/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImplTest.java @@ -57,7 +57,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; -import org.apache.cloudstack.reservation.dao.ReservationDao; import org.apache.cloudstack.resourcelimit.Reserver; import org.apache.cloudstack.storage.datastore.db.ImageStoreDao; import org.apache.cloudstack.storage.datastore.db.ImageStoreVO; From d6657f2b151760df7889a1a65fdbe2bb472f3de4 Mon Sep 17 00:00:00 2001 From: dahn Date: Mon, 20 Apr 2026 10:58:01 +0200 Subject: [PATCH 3/3] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java b/server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java index baa74128ce38..bfec3247a7b8 100644 --- a/server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java +++ b/server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java @@ -764,13 +764,6 @@ public UserVm revertToSnapshot(Long vmSnapshotId) throws InsufficientCapacityExc "In order to revert to a Snapshot without memory you need to first stop the Instance."); } - if (userVm.getState() == VirtualMachine.State.Running && vmSnapshotVo.getType() == VMSnapshot.Type.Disk) { - throw new InvalidParameterValueException( - "Reverting to the Instance Snapshot is not allowed for running Instances as this would result in an Instance state change. " + - "For running Instances only Snapshots with memory can be reverted. " + - "In order to revert to a Snapshot without memory you need to first stop the Instance."); - } - if (userVm.getState() == VirtualMachine.State.Stopped && vmSnapshotVo.getType() == VMSnapshot.Type.DiskAndMemory) { throw new InvalidParameterValueException( "Reverting to the Instance Snapshot is not allowed for stopped Instances when the Snapshot contains memory as this would result in an Instance state change. " +