Skip to content

Commit

Permalink
CLOUDSTACK-9182: Some running VMs turned off on manual migration when…
Browse files Browse the repository at this point in the history
… auto migration failed while host preparing for maintenance.

Fix: Block VMOperations if Host in PrepareForMaintenance mode. VM operations (Stop, Reboot, Destroy, Migrate to host) are not allowed when Host in PrepareForMaintenance mode.
  • Loading branch information
Suresh Kumar Anaparti authored and Suresh Kumar Anaparti committed Dec 2, 2016
1 parent 7670ce0 commit 3920f77
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
import com.cloud.offering.ServiceOffering;
import com.cloud.org.Cluster;
import com.cloud.resource.ResourceManager;
import com.cloud.resource.ResourceState;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.DiskOfferingVO;
Expand Down Expand Up @@ -1485,6 +1486,12 @@ private void advanceStop(final VMInstanceVO vm, final boolean cleanUpEvenIfUnabl
_workDao.update(work.getId(), work);
}
return;
} else {
HostVO host = _hostDao.findById(hostId);
if (!cleanUpEvenIfUnableToStop && vm.getState() == State.Running && host.getResourceState() == ResourceState.PrepareForMaintenance) {
s_logger.debug("Host in PrepareForMaintenance state - Failed to stop VM with id: " + vm.getId());
throw new CloudRuntimeException("VM operation failed as host is preparing for maintenance mode");
}
}

final VirtualMachineGuru vmGuru = getVmGuru(vm);
Expand Down
14 changes: 14 additions & 0 deletions server/src/com/cloud/vm/UserVmManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2597,6 +2597,8 @@ public UserVm rebootVirtualMachine(RebootVMCmd cmd) throws InsufficientCapacityE

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

checkIfHostOfVMIsInPrepareForMaintenanceState(vmInstance.getHostId(), vmId, "Reboot");

// 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
long serviceOfferingId = vmInstance.getServiceOfferingId();
ServiceOfferingVO offering = _serviceOfferingDao.findById(vmInstance.getId(), serviceOfferingId);
Expand Down Expand Up @@ -4595,6 +4597,8 @@ public VirtualMachine migrateVirtualMachine(Long vmId, Host destinationHost) thr
throw ex;
}

checkIfHostOfVMIsInPrepareForMaintenanceState(vm.getHostId(), vmId, "Migrate");

if(serviceOfferingDetailsDao.findDetail(vm.getServiceOfferingId(), GPU.Keys.pciDevice.toString()) != null) {
throw new InvalidParameterValueException("Live Migration of GPU enabled VM is not supported");
}
Expand Down Expand Up @@ -4687,6 +4691,16 @@ private boolean checkIfHostIsDedicated(HostVO host) {
}
}

private void checkIfHostOfVMIsInPrepareForMaintenanceState(Long hostId, Long vmId, String operation) {
HostVO host = _hostDao.findById(hostId);
if (host.getResourceState() != ResourceState.PrepareForMaintenance) {
return;
}

s_logger.debug("Host in PrepareForMaintenance state - " + operation + " VM with id: " + vmId + " not allowed");
throw new InvalidParameterValueException(operation + " VM with id: " + vmId + " not allowed as host is preparing for maintenance mode");
}

private Long accountOfDedicatedHost(HostVO host) {
long hostId = host.getId();
DedicatedResourceVO dedicatedHost = _dedicatedDao.findByHostId(hostId);
Expand Down

0 comments on commit 3920f77

Please sign in to comment.