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:
Wei Zhou 2020-08-05 10:19:03 +02:00 committed by GitHub
parent a7f56d41c8
commit 4527424fce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1124,6 +1124,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
}
try {
resetVmNicsDeviceId(vm.getId());
_networkMgr.prepare(vmProfile, new DeployDestination(dest.getDataCenter(), dest.getPod(), null, null, dest.getStorageForDisks()), ctx);
if (vm.getHypervisorType() != HypervisorType.BareMetal) {
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
private void addExtraConfig(VirtualMachineTO vmTO) {
Map<String, String> details = vmTO.getDetails();