CLOUDSTACK-5666 Cant remove a nic when a vm is in the Stopped state

When VM is not running, existing code is unable to retrieve associated cluster's Id. Now we will try to get this information using previous host where the VM was running.

Signed-off-by: Sateesh Chodapuneedi <sateesh@apache.org>

Conflicts:

	plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
This commit is contained in:
Sateesh Chodapuneedi 2013-12-28 09:13:58 +05:30
parent db99146187
commit 9ca34f14a2

View File

@ -203,7 +203,8 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru, Co
break;
}
}
long clusterId = _hostDao.findById(_vmDao.findById(vm.getId()).getHostId()).getClusterId();
long clusterId = this.getClusterId(vm.getId());
details.put(Config.VmwareReserveCpu.key(), VmwareReserveCpu.valueIn(clusterId).toString());
details.put(Config.VmwareReserveMem.key(), VmwareReserveMemory.valueIn(clusterId).toString());
to.setDetails(details);
@ -298,6 +299,20 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru, Co
return to;
}
private long getClusterId(long vmId) {
long clusterId;
Long hostId;
hostId = _vmDao.findById(vmId).getHostId();
if (hostId == null) {
// If VM is in stopped state then hostId would be undefined. Hence read last host's Id instead.
hostId = _vmDao.findById(vmId).getLastHostId();
}
clusterId = _hostDao.findById(hostId).getClusterId();
return clusterId;
}
private NicTO[] sortNicsByDeviceId(NicTO[] nics) {
List<NicTO> listForSort = new ArrayList<NicTO>();