mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-17 19:14:40 +01:00
vm: Reset deviceId to fix missing nic with vm (#4000)
Co-authored-by: Wei Zhou <57355700+weizhouapache@users.noreply.github.com>
This commit is contained in:
parent
a7f56d41c8
commit
4527424fce
@ -1124,6 +1124,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
resetVmNicsDeviceId(vm.getId());
|
||||||
_networkMgr.prepare(vmProfile, new DeployDestination(dest.getDataCenter(), dest.getPod(), null, null, dest.getStorageForDisks()), ctx);
|
_networkMgr.prepare(vmProfile, new DeployDestination(dest.getDataCenter(), dest.getPod(), null, null, dest.getStorageForDisks()), ctx);
|
||||||
if (vm.getHypervisorType() != HypervisorType.BareMetal) {
|
if (vm.getHypervisorType() != HypervisorType.BareMetal) {
|
||||||
volumeMgr.prepare(vmProfile, dest);
|
volumeMgr.prepare(vmProfile, dest);
|
||||||
@ -1317,6 +1318,26 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void resetVmNicsDeviceId(Long vmId) {
|
||||||
|
final List<NicVO> nics = _nicsDao.listByVmId(vmId);
|
||||||
|
Collections.sort(nics, new Comparator<NicVO>() {
|
||||||
|
@Override
|
||||||
|
public int compare(NicVO nic1, NicVO nic2) {
|
||||||
|
Long nicDevId1 = Long.valueOf(nic1.getDeviceId());
|
||||||
|
Long nicDevId2 = Long.valueOf(nic2.getDeviceId());
|
||||||
|
return nicDevId1.compareTo(nicDevId2);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
int deviceId = 0;
|
||||||
|
for (final NicVO nic : nics) {
|
||||||
|
if (nic.getDeviceId() != deviceId) {
|
||||||
|
nic.setDeviceId(deviceId);
|
||||||
|
_nicsDao.update(nic.getId(),nic);
|
||||||
|
}
|
||||||
|
deviceId ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add extra config data to the vmTO as a Map
|
// Add extra config data to the vmTO as a Map
|
||||||
private void addExtraConfig(VirtualMachineTO vmTO) {
|
private void addExtraConfig(VirtualMachineTO vmTO) {
|
||||||
Map<String, String> details = vmTO.getDetails();
|
Map<String, String> details = vmTO.getDetails();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user