Get new elasticIp when disassociateIP is called for static nat non-elastic IP

This commit is contained in:
Alena Prokharchyk 2012-01-24 15:06:32 -08:00
parent 748603f62d
commit 03b4ac91e1
3 changed files with 11 additions and 3 deletions

View File

@ -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) {

View File

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

View File

@ -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);