|
54 | 54 | import javax.xml.parsers.DocumentBuilder; |
55 | 55 | import javax.xml.parsers.ParserConfigurationException; |
56 | 56 |
|
| 57 | +import com.cloud.utils.db.TransactionLegacy; |
57 | 58 | import org.apache.cloudstack.acl.ControlledEntity; |
58 | 59 | import org.apache.cloudstack.acl.ControlledEntity.ACLType; |
59 | 60 | import org.apache.cloudstack.acl.SecurityChecker.AccessType; |
@@ -7594,6 +7595,11 @@ protected void executeStepsToChangeOwnershipOfVm(AssignVMCmd cmd, Account caller |
7594 | 7595 | try { |
7595 | 7596 | updateVmNetwork(cmd, caller, vm, newAccount, template); |
7596 | 7597 | } catch (InsufficientCapacityException | ResourceAllocationException e) { |
| 7598 | + List<NetworkVO> networkVOS = _networkDao.listByAccountIdNetworkName(newAccountId, newAccount.getAccountName() + "-network"); |
| 7599 | + if (networkVOS.size() == 1) { |
| 7600 | + _networkDao.remove(networkVOS.get(0).getId()); |
| 7601 | + } |
| 7602 | + _accountMgr.getActiveAccountByName(newAccount.getAccountName() + "-network", newAccount.getDomainId()); |
7597 | 7603 | throw new CloudRuntimeException(String.format("Unable to update networks when assigning VM [%s] due to [%s].", vm, e.getMessage()), e); |
7598 | 7604 | } |
7599 | 7605 |
|
@@ -7961,7 +7967,10 @@ protected void selectApplicableNetworkToCreateVm(Account caller, Account newAcco |
7961 | 7967 | NetworkVO defaultNetwork; |
7962 | 7968 | List<? extends Network> virtualNetworks = _networkModel.listNetworksForAccount(newAccount.getId(), zone.getId(), Network.GuestType.Isolated); |
7963 | 7969 | if (virtualNetworks.isEmpty()) { |
7964 | | - defaultNetwork = createApplicableNetworkToCreateVm(caller, newAccount, zone, firstRequiredOffering); |
| 7970 | + try (TransactionLegacy txn = TransactionLegacy.open("CreateNetworkTxn")) { |
| 7971 | + defaultNetwork = createApplicableNetworkToCreateVm(caller, newAccount, zone, firstRequiredOffering); |
| 7972 | + txn.commit(); |
| 7973 | + } |
7965 | 7974 | } else if (virtualNetworks.size() > 1) { |
7966 | 7975 | throw new InvalidParameterValueException(String.format("More than one default isolated network has been found for account [%s]; please specify networkIDs.", |
7967 | 7976 | newAccount)); |
|
0 commit comments