diff --git a/api/src/com/cloud/api/commands/DisassociateIPAddrCmd.java b/api/src/com/cloud/api/commands/DisassociateIPAddrCmd.java index 4c72a8f0f19..0e2944b750f 100644 --- a/api/src/com/cloud/api/commands/DisassociateIPAddrCmd.java +++ b/api/src/com/cloud/api/commands/DisassociateIPAddrCmd.java @@ -29,6 +29,7 @@ import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; +import com.cloud.exception.InsufficientAddressCapacityException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.network.IpAddress; import com.cloud.user.Account; @@ -70,7 +71,7 @@ public class DisassociateIPAddrCmd extends BaseAsyncCmd { } @Override - public void execute(){ + public void execute() throws InsufficientAddressCapacityException{ UserContext.current().setEventDetails("Ip Id: "+getIpAddressId()); boolean result = _networkService.disassociateIpAddress(id); if (result) { diff --git a/api/src/com/cloud/network/NetworkService.java b/api/src/com/cloud/network/NetworkService.java index 1f26b358ffa..89833212cb6 100755 --- a/api/src/com/cloud/network/NetworkService.java +++ b/api/src/com/cloud/network/NetworkService.java @@ -55,7 +55,7 @@ public interface NetworkService { */ IpAddress associateIP(long ipId) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException, ResourceUnavailableException; - boolean disassociateIpAddress(long ipAddressId); + boolean disassociateIpAddress(long ipAddressId) throws InsufficientAddressCapacityException; Network createNetwork(CreateNetworkCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException; diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 49dd1cc5b88..d78b463af99 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -1877,7 +1877,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override @DB @ActionEvent(eventType = EventTypes.EVENT_NET_IP_RELEASE, eventDescription = "disassociating Ip", async = true) - public boolean disassociateIpAddress(long ipAddressId) { + public boolean disassociateIpAddress(long ipAddressId) throws InsufficientAddressCapacityException{ Long userId = UserContext.current().getCallerUserId(); Account caller = UserContext.current().getCaller(); @@ -1920,6 +1920,13 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag boolean success = releasePublicIpAddress(ipAddressId, userId, caller); if (success) { + Network guestNetwork = getNetwork(ipVO.getAssociatedWithNetworkId()); + NetworkOffering offering = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId()); + Long vmId = ipVO.getAssociatedWithVmId(); + if (offering.getElasticIp() && vmId != null) { + _rulesMgr.enableElasticIpAndStaticNatForVm(_userVmDao.findById(vmId), true); + return true; + } return true; } else { s_logger.warn("Failed to release public ip address id=" + ipAddressId);