CLOUDSTACK-9317: When there 1 static nat removing PF rules is handled

There is 1 static nat rule and 2 PF rule. Removing 2 PF rules was deleting static nat rule.
    Fixed this issue in this commit.
This commit is contained in:
Jayapal 2017-02-07 11:40:53 +05:30
parent c20e0ef88f
commit 8ef52325e7
7 changed files with 41 additions and 9 deletions

View File

@ -92,4 +92,8 @@ public interface IpAddress extends ControlledEntity, Identity, InternalIdentity,
public Date getCreated(); public Date getCreated();
State getRuleState();
void setRuleState(State ruleState);
} }

View File

@ -38,7 +38,7 @@ public abstract class NetworkElementCommand extends Command {
public static final String VPC_PRIVATE_GATEWAY = "vpc.gateway.private"; public static final String VPC_PRIVATE_GATEWAY = "vpc.gateway.private";
public static final String FIREWALL_EGRESS_DEFAULT = "firewall.egress.default"; public static final String FIREWALL_EGRESS_DEFAULT = "firewall.egress.default";
public static final String ROUTER_MONITORING_ENABLE = "router.monitor.enable"; public static final String ROUTER_MONITORING_ENABLE = "router.monitor.enable";
public static final String NETWORK_PUB_LAST_IP = "newtork.public.last.ip"; public static final String NETWORK_PUB_LAST_IP = "network.public.last.ip";
private String routerAccessIp; private String routerAccessIp;

View File

@ -255,4 +255,13 @@ public class PublicIp implements PublicIpAddress {
return IpAddress.class; return IpAddress.class;
} }
@Override
public State getRuleState() {
return _addr.getRuleState();
}
@Override
public void setRuleState(State ruleState) {
_addr.setRuleState(ruleState);
}
} }

View File

@ -117,6 +117,10 @@ public class IPAddressVO implements IpAddress {
@Column(name = "display", updatable = true, nullable = false) @Column(name = "display", updatable = true, nullable = false)
protected boolean display = true; protected boolean display = true;
@Enumerated(value = EnumType.STRING)
@Column(name = "rule_state")
State ruleState;
@Column(name= GenericDao.REMOVED_COLUMN) @Column(name= GenericDao.REMOVED_COLUMN)
private Date removed; private Date removed;
@ -367,4 +371,14 @@ public class IPAddressVO implements IpAddress {
public Date getCreated() { public Date getCreated() {
return created; return created;
} }
@Override
public State getRuleState() {
return ruleState;
}
@Override
public void setRuleState(State ruleState) {
this.ruleState = ruleState;
}
} }

View File

@ -858,7 +858,8 @@ public class CommandSetupHelper {
ipsWithrules++; ipsWithrules++;
} }
if (ip.isOneToOneNat()) { // check onetoonenat and also check if the ip "add":false. If there are 2 PF remove 1 static nat add
if (ip.isOneToOneNat() && ip.getRuleState() == null) {
ipsStaticNat++; ipsStaticNat++;
} }
} }
@ -870,13 +871,8 @@ public class CommandSetupHelper {
final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId()); final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString()); cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
boolean remove = false; // if there 1 static nat then it will be checked for remove at the resource
// if there is only one static nat then it will be checked for remove at the resource if (ipsWithrules == 0 && ipsStaticNat == 0 ) {
if (ipsWithrules == 0 && (ipsStaticNat == 0 || ipsStaticNat == 1)) {
remove = true;
}
if (remove) {
// there is only one ip address for the network. // there is only one ip address for the network.
cmd.setAccessDetail(NetworkElementCommand.NETWORK_PUB_LAST_IP, "true"); cmd.setAccessDetail(NetworkElementCommand.NETWORK_PUB_LAST_IP, "true");
} }

View File

@ -1259,6 +1259,10 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
throw ex; throw ex;
} }
ipAddress.setRuleState(IpAddress.State.Releasing);
_ipAddressDao.update(ipAddress.getId(), ipAddress);
ipAddress = _ipAddressDao.findById(ipId);
// Revoke all firewall rules for the ip // Revoke all firewall rules for the ip
try { try {
s_logger.debug("Revoking all " + Purpose.Firewall + "rules as a part of disabling static nat for public IP id=" + ipId); s_logger.debug("Revoking all " + Purpose.Firewall + "rules as a part of disabling static nat for public IP id=" + ipId);
@ -1280,6 +1284,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
boolean isIpSystem = ipAddress.getSystem(); boolean isIpSystem = ipAddress.getSystem();
ipAddress.setOneToOneNat(false); ipAddress.setOneToOneNat(false);
ipAddress.setAssociatedWithVmId(null); ipAddress.setAssociatedWithVmId(null);
ipAddress.setRuleState(null);
ipAddress.setVmIp(null); ipAddress.setVmIp(null);
if (isIpSystem && !releaseIpIfElastic) { if (isIpSystem && !releaseIpIfElastic) {
ipAddress.setSystem(false); ipAddress.setSystem(false);
@ -1295,6 +1300,9 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
return true; return true;
} else { } else {
s_logger.warn("Failed to disable one to one nat for the ip address id" + ipId); s_logger.warn("Failed to disable one to one nat for the ip address id" + ipId);
ipAddress = _ipAddressDao.findById(ipId);
ipAddress.setRuleState(null);
_ipAddressDao.update(ipAddress.getId(), ipAddress);
return false; return false;
} }
} }

View File

@ -245,3 +245,4 @@ CREATE TABLE `cloud`.`guest_os_details` (
CONSTRAINT `fk_guest_os_details__guest_os_id` FOREIGN KEY `fk_guest_os_details__guest_os_id`(`guest_os_id`) REFERENCES `guest_os`(`id`) ON DELETE CASCADE CONSTRAINT `fk_guest_os_details__guest_os_id` FOREIGN KEY `fk_guest_os_details__guest_os_id`(`guest_os_id`) REFERENCES `guest_os`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `user_ip_address` ADD COLUMN `rule_state` VARCHAR(32) COMMENT 'static rule state while removing';