mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
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:
parent
db99146187
commit
9ca34f14a2
@ -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>();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user