Mark ip as not elastic when disable static nat is called on it

This commit is contained in:
Alena Prokharchyk 2012-01-16 09:04:40 -08:00
parent 212c22b256
commit 4f46c3b160
3 changed files with 12 additions and 8 deletions

View File

@ -73,6 +73,6 @@ public interface RulesManager extends RulesService {
boolean enableElasticIpAndStaticNatForVm(UserVm vm, boolean stopOnError);
boolean disableStaticNat(long ipAddressId, Account caller, long callerUserId) throws ResourceUnavailableException;
boolean disableStaticNat(long ipAddressId, Account caller, long callerUserId, boolean releaseIpIfElastic) throws ResourceUnavailableException;
}

View File

@ -419,7 +419,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
}
//unassign old static nat rule
s_logger.debug("Disassociating static nat for ip " + oldIP);
if (!disableStaticNat(oldIP.getId(), caller, callerUserId)) {
if (!disableStaticNat(oldIP.getId(), caller, callerUserId, true)) {
throw new CloudRuntimeException("Failed to disable old static nat rule for vm id=" + vmId + " and ip " + oldIP);
}
}
@ -1025,7 +1025,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
Long vmId = ipAddress.getAssociatedWithVmId();
boolean success = disableStaticNat(ipId, caller, ctx.getCallerUserId());
boolean success = disableStaticNat(ipId, caller, ctx.getCallerUserId(), false);
if (success && vmId != null) {
s_logger.debug("Allocating ip and enabling static nat for vm id=" + vmId + " as a part of disassociateIp command");
UserVm vm = _vmDao.findById(vmId);
@ -1040,8 +1040,8 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
return success;
}
@Override
public boolean disableStaticNat(long ipId, Account caller, long callerUserId) throws ResourceUnavailableException {
@Override @DB
public boolean disableStaticNat(long ipId, Account caller, long callerUserId, boolean releaseIpIfElastic) throws ResourceUnavailableException {
boolean success = true;
IPAddressVO ipAddress = _ipAddressDao.findById(ipId);
@ -1069,12 +1069,16 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
}
if (success) {
boolean isIpElastic = ipAddress.getElastic();
ipAddress.setOneToOneNat(false);
ipAddress.setAssociatedWithVmId(null);
if (isIpElastic && !releaseIpIfElastic) {
ipAddress.setElastic(false);
}
_ipAddressDao.update(ipAddress.getId(), ipAddress);
if (!_networkMgr.handleElasticIpRelease(ipAddress)) {
if (isIpElastic && releaseIpIfElastic && !_networkMgr.handleElasticIpRelease(ipAddress)) {
s_logger.warn("Failed to release elastic ip address " + ipAddress);
success = false;
}

View File

@ -1264,7 +1264,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(vmId);
try {
if (ip != null) {
if (_rulesMgr.disableStaticNat(ip.getId(), _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM), User.UID_SYSTEM)) {
if (_rulesMgr.disableStaticNat(ip.getId(), _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM), User.UID_SYSTEM, true)) {
s_logger.debug("Disabled 1-1 nat for ip address " + ip + " as a part of vm id=" + vmId + " expunge");
} else {
s_logger.warn("Failed to disable static nat for ip address " + ip + " as a part of vm id=" + vmId + " expunge");