You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
server: keep networks order and ips while move a vm with multiple networks (#4602)
This PR fixes an issue when move a vm from an account to another account.
Steps to reproduce the issue
(1) create a vm with multiple shared networks (in advanced zone, or advanced zone with security groups)
(2) create another account (in same domain who can also access the shared networks)
(3) move vm to new account, with a list of networkid
expected result: the vm has nics on the networks in same order as specified in API request, and nics have the same ips as before actual result: network order is not same as specified, ips are changed.
Copy file name to clipboardExpand all lines: engine/api/src/main/java/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java
s_logger.debug("AssignVM: use old shared network " + defaultNetworkOld.getName() + " with old ip " + requestedIPv4ForDefaultNic + " on default nic of vm:" + vm.getInstanceName());
6305
-
} catch (PermissionDeniedExceptione) {
6306
-
s_logger.debug("AssignVM: the shared network on old default nic can not be applied to new account");
6307
-
}
6297
+
if (canAccountUseNetwork(newAccount, defaultNetworkOld)) {
s_logger.debug("AssignVM: use old shared network " + defaultNetworkOld.getName() + " with old ip " + defaultNicOld.getIPv4Address() + " on default nic of vm:" + vm.getInstanceName());
6308
6302
}
6309
6303
}
6310
6304
}
6311
-
// cleanup the network for the oldOwner
6312
-
_networkMgr.cleanupNics(vmOldProfile);
6313
-
_networkMgr.expungeNics(vmOldProfile);
6314
6305
6315
6306
if (networkIdList != null && !networkIdList.isEmpty()) {
6316
6307
// add any additional networks
@@ -6333,10 +6324,24 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
s_logger.debug("AssignVM: use old shared network " + network.getName() + " with old ip " + nicOld.getIPv4Address() + " on nic of vm:" + vm.getInstanceName());
6334
+
}
6335
+
}
6336
+
s_logger.debug("AssignVM: Added network " + network.getName() + " to vm " + vm.getId());
s_logger.debug("AssignVM: use old shared network " + defaultNetworkOld.getName() + " with old ip " + defaultNicOld.getIPv4Address() + " on default nic of vm:" + vm.getInstanceName());
6428
6431
}
6429
6432
}
6430
6433
}
6431
6434
6432
-
// cleanup the network for the oldOwner
6433
-
_networkMgr.cleanupNics(vmOldProfile);
6434
-
_networkMgr.expungeNics(vmOldProfile);
6435
-
6436
6435
if (networkIdList != null && !networkIdList.isEmpty()) {
6437
6436
// add any additional networks
6438
6437
for (LongnetworkId : networkIdList) {
@@ -6452,6 +6451,16 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
s_logger.debug("AssignVM: use old shared network " + network.getName() + " with old ip " + nicOld.getIPv4Address() + " on nic of vm:" + vm.getInstanceName());
6461
+
}
6462
+
}
6463
+
s_logger.debug("AssignVM: Added network " + network.getName() + " to vm " + vm.getId());
6455
6464
applicableNetworks.add(network);
6456
6465
}
6457
6466
} elseif (applicableNetworks.isEmpty()) {
@@ -6515,6 +6524,10 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
s_logger.debug(String.format("AssignVM: %s network %s can not be used by new account %s", network.getGuestType(), network.getName(), newAccount.getAccountName()));
0 commit comments