mirror of https://github.com/apache/cloudstack.git
CS-15603 : CloudStack failing to stop vm's when destroyVM is called
When a VM is force deleted and the host is not available then CS simply marks the state in db as "Destroyed/Expunging". The VM is still running on the host and once it becomes available again there is a discrepancy in state of the VM. In this scenario the VM is removed from the host when the next full cluster sync happens. Reviewed-by: Abhi
This commit is contained in:
parent
3aa0e9a352
commit
cae5db1722
|
|
@ -1746,7 +1746,6 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
set_vms.addAll(_vmDao.listLHByClusterId(clusterId));
|
||||
|
||||
for (VMInstanceVO vm : set_vms) {
|
||||
if (vm.isRemoved() || vm.getState() == State.Destroyed || vm.getState() == State.Expunging) continue;
|
||||
AgentVmInfo info = infos.remove(vm.getId());
|
||||
VMInstanceVO castedVm = null;
|
||||
if ((info == null && (vm.getState() == State.Running || vm.getState() == State.Starting))
|
||||
|
|
@ -1790,13 +1789,16 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else if (info != null && (vm.getState() == State.Stopped || vm.getState() == State.Stopping)) {
|
||||
else if (info != null && (vm.getState() == State.Stopped || vm.getState() == State.Stopping
|
||||
|| vm.isRemoved() || vm.getState() == State.Destroyed || vm.getState() == State.Expunging)) {
|
||||
Host host = _hostDao.findByGuid(info.getHostUuid());
|
||||
if (host != null){
|
||||
s_logger.warn("Stopping a VM which is stopped/stopping " + info.name);
|
||||
vm.setState(State.Stopped); // set it as stop and clear it from host
|
||||
vm.setHostId(null);
|
||||
_vmDao.persist(vm);
|
||||
if (host != null) {
|
||||
s_logger.warn("Stopping a VM which is stopped/stopping/destroyed/expunging " + info.name);
|
||||
if (vm.getState() == State.Stopped || vm.getState() == State.Stopping) {
|
||||
vm.setState(State.Stopped); // set it as stop and clear it from host
|
||||
vm.setHostId(null);
|
||||
_vmDao.persist(vm);
|
||||
}
|
||||
try {
|
||||
Answer answer = _agentMgr.send(host.getId(), cleanup(info.name));
|
||||
if (!answer.getResult()) {
|
||||
|
|
@ -1832,7 +1834,6 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
}
|
||||
|
||||
for (final AgentVmInfo left : infos.values()) {
|
||||
if (VirtualMachineName.isValidVmName(left.name)) continue; // if the vm follows cloudstack naming ignore it for stopping
|
||||
try {
|
||||
Host host = _hostDao.findByGuid(left.getHostUuid());
|
||||
if (host != null){
|
||||
|
|
|
|||
Loading…
Reference in New Issue