From 9ca34f14a2fad303ba85f167150e3daf331082fa Mon Sep 17 00:00:00 2001 From: Sateesh Chodapuneedi Date: Sat, 28 Dec 2013 09:13:58 +0530 Subject: [PATCH] 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 Conflicts: plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java --- .../com/cloud/hypervisor/guru/VMwareGuru.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java index b326c54d69b..d72787ca86e 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java @@ -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 listForSort = new ArrayList();