mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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:
parent
c20e0ef88f
commit
8ef52325e7
@ -92,4 +92,8 @@ public interface IpAddress extends ControlledEntity, Identity, InternalIdentity,
|
||||
|
||||
public Date getCreated();
|
||||
|
||||
State getRuleState();
|
||||
|
||||
void setRuleState(State ruleState);
|
||||
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ public abstract class NetworkElementCommand extends Command {
|
||||
public static final String VPC_PRIVATE_GATEWAY = "vpc.gateway.private";
|
||||
public static final String FIREWALL_EGRESS_DEFAULT = "firewall.egress.default";
|
||||
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;
|
||||
|
||||
|
||||
@ -255,4 +255,13 @@ public class PublicIp implements PublicIpAddress {
|
||||
return IpAddress.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public State getRuleState() {
|
||||
return _addr.getRuleState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRuleState(State ruleState) {
|
||||
_addr.setRuleState(ruleState);
|
||||
}
|
||||
}
|
||||
|
||||
@ -117,6 +117,10 @@ public class IPAddressVO implements IpAddress {
|
||||
@Column(name = "display", updatable = true, nullable = false)
|
||||
protected boolean display = true;
|
||||
|
||||
@Enumerated(value = EnumType.STRING)
|
||||
@Column(name = "rule_state")
|
||||
State ruleState;
|
||||
|
||||
@Column(name= GenericDao.REMOVED_COLUMN)
|
||||
private Date removed;
|
||||
|
||||
@ -367,4 +371,14 @@ public class IPAddressVO implements IpAddress {
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
@Override
|
||||
public State getRuleState() {
|
||||
return ruleState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRuleState(State ruleState) {
|
||||
this.ruleState = ruleState;
|
||||
}
|
||||
}
|
||||
|
||||
@ -858,7 +858,8 @@ public class CommandSetupHelper {
|
||||
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++;
|
||||
}
|
||||
}
|
||||
@ -870,13 +871,8 @@ public class CommandSetupHelper {
|
||||
final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
|
||||
cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
|
||||
|
||||
boolean remove = false;
|
||||
// if there is only one static nat then it will be checked for remove at the resource
|
||||
if (ipsWithrules == 0 && (ipsStaticNat == 0 || ipsStaticNat == 1)) {
|
||||
remove = true;
|
||||
}
|
||||
|
||||
if (remove) {
|
||||
// if there 1 static nat then it will be checked for remove at the resource
|
||||
if (ipsWithrules == 0 && ipsStaticNat == 0 ) {
|
||||
// there is only one ip address for the network.
|
||||
cmd.setAccessDetail(NetworkElementCommand.NETWORK_PUB_LAST_IP, "true");
|
||||
}
|
||||
|
||||
@ -1259,6 +1259,10 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
|
||||
throw ex;
|
||||
}
|
||||
|
||||
ipAddress.setRuleState(IpAddress.State.Releasing);
|
||||
_ipAddressDao.update(ipAddress.getId(), ipAddress);
|
||||
ipAddress = _ipAddressDao.findById(ipId);
|
||||
|
||||
// Revoke all firewall rules for the ip
|
||||
try {
|
||||
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();
|
||||
ipAddress.setOneToOneNat(false);
|
||||
ipAddress.setAssociatedWithVmId(null);
|
||||
ipAddress.setRuleState(null);
|
||||
ipAddress.setVmIp(null);
|
||||
if (isIpSystem && !releaseIpIfElastic) {
|
||||
ipAddress.setSystem(false);
|
||||
@ -1295,6 +1300,9 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
|
||||
return true;
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
ALTER TABLE `user_ip_address` ADD COLUMN `rule_state` VARCHAR(32) COMMENT 'static rule state while removing';
|
||||
Loading…
x
Reference in New Issue
Block a user