rhtyd commented on a change in pull request #2211: CLOUDSTACK-10013: Migrate
systemvmtemplate to Debian9
URL: https://github.com/apache/cloudstack/pull/2211#discussion_r158593073
##########
File path: server/src/com/cloud/network/IpAddressManagerImpl.java
##########
@@ -799,28 +798,55 @@ public IPAddressVO doInTransaction(TransactionStatus
status) throws Insufficient
throw new AccountLimitException("Maximum number of
public IP addresses for account: " + owner.getAccountName() + " has been
exceeded.");
}
}
- IPAddressVO addr = addrs.get(0);
- addr.setSourceNat(sourceNat);
- addr.setAllocatedTime(new Date());
- addr.setAllocatedInDomainId(owner.getDomainId());
- addr.setAllocatedToAccountId(owner.getId());
- addr.setSystem(isSystem);
-
- if (displayIp != null) {
- addr.setDisplay(displayIp);
+
+ IPAddressVO finalAddr = null;
+ for (final IPAddressVO possibleAddr: addrs) {
+ if (possibleAddr.getState() != IpAddress.State.Free) {
+ continue;
+ }
+ final IPAddressVO addr = possibleAddr;
+ addr.setSourceNat(sourceNat);
+ addr.setAllocatedTime(new Date());
+ addr.setAllocatedInDomainId(owner.getDomainId());
+ addr.setAllocatedToAccountId(owner.getId());
+ addr.setSystem(isSystem);
+
+ if (displayIp != null) {
+ addr.setDisplay(displayIp);
+ }
+
+ if (vlanUse != VlanType.DirectAttached) {
+ addr.setAssociatedWithNetworkId(guestNetworkId);
+ addr.setVpcId(vpcId);
+ }
+ if (_ipAddressDao.lockRow(possibleAddr.getId(), true) !=
null) {
+ final IPAddressVO userIp =
_ipAddressDao.findById(addr.getId());
+ if (userIp.getState() == IpAddress.State.Free) {
+ addr.setState(IpAddress.State.Allocating);
+ if (_ipAddressDao.update(addr.getId(), addr)) {
Review comment:
The current regression fix is a two step process where IPs are first marked
allocating and then marked allocated if assign is true, it's because ips in
both free and allocating state can be allocated. ~~Do you propose we simply
mark free ips to allocated in the loop if assign is true?~~ @yvsubhash if you
can come up with further improvements/enhancements, please send a new PR,
thanks.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services