Updated Branches:
  refs/heads/4.3 8eb430f60 -> c15cf1230

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 <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/c15cf123
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/c15cf123
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/c15cf123

Branch: refs/heads/4.3
Commit: c15cf1230841bcc107d923e1f126fe15763617ad
Parents: 8eb430f
Author: Sateesh Chodapuneedi <[email protected]>
Authored: Sat Dec 28 09:09:37 2013 +0530
Committer: Sateesh Chodapuneedi <[email protected]>
Committed: Sat Dec 28 09:09:37 2013 +0530

----------------------------------------------------------------------
 .../src/com/cloud/hypervisor/guru/VMwareGuru.java   | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c15cf123/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
----------------------------------------------------------------------
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 326a950..349b516 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
@@ -197,7 +197,7 @@ public class VMwareGuru extends HypervisorGuruBase 
implements HypervisorGuru, Co
             }
         }
 
-        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);
@@ -293,6 +293,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>();

Reply via email to