Skip to content

Commit f2584bb

Browse files
sureshanapartiyadvr
authored andcommitted
CLOUDSTACK-9182: Some running VMs turned off on manual migration when auto migration failed while host preparing for maintenance. (#1252)
Fix: Block VMOperations if Host in PrepareForMaintenance mode. VM operations (Stop, Reboot, Destroy, Migrate to host) are not allowed when Host in PrepareForMaintenance mode.
1 parent 3f69c83 commit f2584bb

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
import com.cloud.offering.ServiceOffering;
160160
import com.cloud.org.Cluster;
161161
import com.cloud.resource.ResourceManager;
162+
import com.cloud.resource.ResourceState;
162163
import com.cloud.service.ServiceOfferingVO;
163164
import com.cloud.service.dao.ServiceOfferingDao;
164165
import com.cloud.storage.DiskOfferingVO;
@@ -1531,6 +1532,12 @@ private void advanceStop(final VMInstanceVO vm, final boolean cleanUpEvenIfUnabl
15311532
_workDao.update(work.getId(), work);
15321533
}
15331534
return;
1535+
} else {
1536+
HostVO host = _hostDao.findById(hostId);
1537+
if (!cleanUpEvenIfUnableToStop && vm.getState() == State.Running && host.getResourceState() == ResourceState.PrepareForMaintenance) {
1538+
s_logger.debug("Host is in PrepareForMaintenance state - Stop VM operation on the VM id: " + vm.getId() + " is not allowed");
1539+
throw new CloudRuntimeException("Stop VM operation on the VM id: " + vm.getId() + " is not allowed as host is preparing for maintenance mode");
1540+
}
15341541
}
15351542

15361543
final VirtualMachineGuru vmGuru = getVmGuru(vm);

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

100755100644
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2636,6 +2636,8 @@ public UserVm rebootVirtualMachine(RebootVMCmd cmd) throws InsufficientCapacityE
26362636

26372637
_accountMgr.checkAccess(caller, null, true, vmInstance);
26382638

2639+
checkIfHostOfVMIsInPrepareForMaintenanceState(vmInstance.getHostId(), vmId, "Reboot");
2640+
26392641
// If the VM is Volatile in nature, on reboot discard the VM's root disk and create a new root disk for it: by calling restoreVM
26402642
long serviceOfferingId = vmInstance.getServiceOfferingId();
26412643
ServiceOfferingVO offering = _serviceOfferingDao.findById(vmInstance.getId(), serviceOfferingId);
@@ -4845,6 +4847,8 @@ public VirtualMachine migrateVirtualMachine(Long vmId, Host destinationHost) thr
48454847
throw ex;
48464848
}
48474849

4850+
checkIfHostOfVMIsInPrepareForMaintenanceState(vm.getHostId(), vmId, "Migrate");
4851+
48484852
if(serviceOfferingDetailsDao.findDetail(vm.getServiceOfferingId(), GPU.Keys.pciDevice.toString()) != null) {
48494853
throw new InvalidParameterValueException("Live Migration of GPU enabled VM is not supported");
48504854
}
@@ -4938,6 +4942,16 @@ private boolean checkIfHostIsDedicated(HostVO host) {
49384942
}
49394943
}
49404944

4945+
private void checkIfHostOfVMIsInPrepareForMaintenanceState(Long hostId, Long vmId, String operation) {
4946+
HostVO host = _hostDao.findById(hostId);
4947+
if (host.getResourceState() != ResourceState.PrepareForMaintenance) {
4948+
return;
4949+
}
4950+
4951+
s_logger.debug("Host is in PrepareForMaintenance state - " + operation + " VM operation on the VM id: " + vmId + " is not allowed");
4952+
throw new InvalidParameterValueException(operation + " VM operation on the VM id: " + vmId + " is not allowed as host is preparing for maintenance mode");
4953+
}
4954+
49414955
private Long accountOfDedicatedHost(HostVO host) {
49424956
long hostId = host.getId();
49434957
DedicatedResourceVO dedicatedHost = _dedicatedDao.findByHostId(hostId);

0 commit comments

Comments
 (0)