Skip to content

Commit 3f16740

Browse files
committed
CLOUDSTACK-7985: keep the default nic on shared network when assignVM
1 parent a1d2fba commit 3f16740

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

server/src/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5246,12 +5246,27 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
52465246
if (securityGroupIdList != null && !securityGroupIdList.isEmpty()) {
52475247
throw new InvalidParameterValueException("Can't move vm with security groups; security group feature is not enabled in this zone");
52485248
}
5249+
Set<NetworkVO> applicableNetworks = new HashSet<NetworkVO>();
5250+
// if networkIdList is null and the first network of vm is shared network, then keep it if possible
5251+
if (networkIdList == null || networkIdList.isEmpty()) {
5252+
NicVO defaultNicOld = _nicDao.findDefaultNicForVM(vm.getId());
5253+
if (defaultNicOld != null) {
5254+
NetworkVO defaultNetworkOld = _networkDao.findById(defaultNicOld.getNetworkId());
5255+
if (defaultNetworkOld != null && defaultNetworkOld.getGuestType() == Network.GuestType.Shared && defaultNetworkOld.getAclType() == ACLType.Domain) {
5256+
try {
5257+
_networkModel.checkNetworkPermissions(newAccount, defaultNetworkOld);
5258+
applicableNetworks.add(defaultNetworkOld);
5259+
} catch (PermissionDeniedException e) {
5260+
s_logger.debug("AssignVM: the shared network on old default nic can not be applied to new account");
5261+
}
5262+
}
5263+
}
5264+
}
5265+
52495266
// cleanup the network for the oldOwner
52505267
_networkMgr.cleanupNics(vmOldProfile);
52515268
_networkMgr.expungeNics(vmOldProfile);
52525269

5253-
Set<NetworkVO> applicableNetworks = new HashSet<NetworkVO>();
5254-
52555270
if (networkIdList != null && !networkIdList.isEmpty()) {
52565271
// add any additional networks
52575272
for (Long networkId : networkIdList) {
@@ -5273,7 +5288,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
52735288
}
52745289
applicableNetworks.add(network);
52755290
}
5276-
} else {
5291+
} else if (applicableNetworks.isEmpty()) {
52775292
NetworkVO defaultNetwork = null;
52785293
List<NetworkOfferingVO> requiredOfferings = _networkOfferingDao.listByAvailability(Availability.Required, false);
52795294
if (requiredOfferings.size() < 1) {

0 commit comments

Comments
 (0)