yvsubhash commented on a change in pull request #2211: CLOUDSTACK-10013: 
Migrate systemvmtemplate to Debian9
URL: https://github.com/apache/cloudstack/pull/2211#discussion_r158587630
 
 

 ##########
 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:
   @rhtyd  unlike previous approach, now it seems to be doing an extra update 
operation to DB when assign is true,   can we avoid that?

----------------------------------------------------------------
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

Reply via email to