-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix issue with Assign VM operation #10834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ | |
import javax.xml.parsers.DocumentBuilder; | ||
import javax.xml.parsers.ParserConfigurationException; | ||
|
||
import com.cloud.utils.db.TransactionLegacy; | ||
import org.apache.cloudstack.acl.ControlledEntity; | ||
import org.apache.cloudstack.acl.ControlledEntity.ACLType; | ||
import org.apache.cloudstack.acl.SecurityChecker.AccessType; | ||
|
@@ -7594,6 +7595,11 @@ protected void executeStepsToChangeOwnershipOfVm(AssignVMCmd cmd, Account caller | |
try { | ||
updateVmNetwork(cmd, caller, vm, newAccount, template); | ||
} catch (InsufficientCapacityException | ResourceAllocationException e) { | ||
List<NetworkVO> networkVOS = _networkDao.listByAccountIdNetworkName(newAccountId, newAccount.getAccountName() + "-network"); | ||
if (networkVOS.size() == 1) { | ||
_networkDao.remove(networkVOS.get(0).getId()); | ||
} | ||
_accountMgr.getActiveAccountByName(newAccount.getAccountName() + "-network", newAccount.getDomainId()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this? name won't be null with current code. Do we expect domainId to return null and then throw InvalidParameterValueException? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's by mistake |
||
throw new CloudRuntimeException(String.format("Unable to update networks when assigning VM [%s] due to [%s].", vm, e.getMessage()), e); | ||
} | ||
|
||
|
@@ -7961,7 +7967,10 @@ protected void selectApplicableNetworkToCreateVm(Account caller, Account newAcco | |
NetworkVO defaultNetwork; | ||
List<? extends Network> virtualNetworks = _networkModel.listNetworksForAccount(newAccount.getId(), zone.getId(), Network.GuestType.Isolated); | ||
if (virtualNetworks.isEmpty()) { | ||
defaultNetwork = createApplicableNetworkToCreateVm(caller, newAccount, zone, firstRequiredOffering); | ||
try (TransactionLegacy txn = TransactionLegacy.open("CreateNetworkTxn")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Transaction.execute() won't work here? |
||
defaultNetwork = createApplicableNetworkToCreateVm(caller, newAccount, zone, firstRequiredOffering); | ||
txn.commit(); | ||
} | ||
} else if (virtualNetworks.size() > 1) { | ||
throw new InvalidParameterValueException(String.format("More than one default isolated network has been found for account [%s]; please specify networkIDs.", | ||
newAccount)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can network be in implemented state or something? Do we really want to mark it as removed directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not ready for review - stil working on a way to see if the network was created during the assignVM operation and only then remove it