|
35 | 35 |
|
36 | 36 | import com.cloud.network.dao.PublicIpQuarantineDao; |
37 | 37 | import com.cloud.network.vo.PublicIpQuarantineVO; |
| 38 | +import com.cloud.resourcelimit.CheckedReservation; |
38 | 39 | import org.apache.cloudstack.acl.ControlledEntity.ACLType; |
39 | 40 | import org.apache.cloudstack.acl.SecurityChecker.AccessType; |
40 | 41 | import org.apache.cloudstack.annotation.AnnotationService; |
|
53 | 54 | import org.apache.cloudstack.region.PortableIpDao; |
54 | 55 | import org.apache.cloudstack.region.PortableIpVO; |
55 | 56 | import org.apache.cloudstack.region.Region; |
| 57 | +import org.apache.cloudstack.reservation.dao.ReservationDao; |
56 | 58 | import org.apache.commons.collections.CollectionUtils; |
57 | 59 | import org.apache.log4j.Logger; |
58 | 60 |
|
@@ -261,6 +263,8 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage |
261 | 263 | @Inject |
262 | 264 | ResourceLimitService _resourceLimitMgr; |
263 | 265 |
|
| 266 | + @Inject |
| 267 | + ReservationDao reservationDao; |
264 | 268 | @Inject |
265 | 269 | NetworkOfferingServiceMapDao _ntwkOfferingSrvcDao; |
266 | 270 | @Inject |
@@ -1556,21 +1560,25 @@ public IPAddressVO associateIPToGuestNetwork(long ipId, long networkId, boolean |
1556 | 1560 |
|
1557 | 1561 | s_logger.debug("Associating ip " + ipToAssoc + " to network " + network); |
1558 | 1562 |
|
1559 | | - IPAddressVO ip = _ipAddressDao.findById(ipId); |
1560 | | - //update ip address with networkId |
1561 | | - ip.setAssociatedWithNetworkId(networkId); |
1562 | | - ip.setSourceNat(isSourceNat); |
1563 | | - _ipAddressDao.update(ipId, ip); |
1564 | | - |
1565 | 1563 | boolean success = false; |
1566 | | - try { |
| 1564 | + IPAddressVO ip = null; |
| 1565 | + try (CheckedReservation publicIpReservation = new CheckedReservation(owner, ResourceType.public_ip, 1l, reservationDao, _resourceLimitMgr)) { |
| 1566 | + ip = _ipAddressDao.findById(ipId); |
| 1567 | + //update ip address with networkId |
| 1568 | + ip.setAssociatedWithNetworkId(networkId); |
| 1569 | + ip.setSourceNat(isSourceNat); |
| 1570 | + _ipAddressDao.update(ipId, ip); |
| 1571 | + |
1567 | 1572 | success = applyIpAssociations(network, false); |
1568 | 1573 | if (success) { |
1569 | 1574 | s_logger.debug("Successfully associated ip address " + ip.getAddress().addr() + " to network " + network); |
1570 | 1575 | } else { |
1571 | 1576 | s_logger.warn("Failed to associate ip address " + ip.getAddress().addr() + " to network " + network); |
1572 | 1577 | } |
1573 | 1578 | return _ipAddressDao.findById(ipId); |
| 1579 | + } catch (Exception e) { |
| 1580 | + s_logger.error(String.format("Failed to associate ip address %s to network %s", ipToAssoc, network), e); |
| 1581 | + throw new CloudRuntimeException(String.format("Failed to associate ip address %s to network %s", ipToAssoc, network), e); |
1574 | 1582 | } finally { |
1575 | 1583 | if (!success && releaseOnFailure) { |
1576 | 1584 | if (ip != null) { |
|
0 commit comments