Skip to content

Commit 524fc32

Browse files
authored
Merge pull request #1917 from Accelerite/RvRipRel
CLOUDSTACK-9756: Configure to ignore the ipassoc failure
2 parents 0c9ddcb + d71879c commit 524fc32

6 files changed

Lines changed: 42 additions & 12 deletions

File tree

engine/components-api/src/com/cloud/network/IpAddressManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public interface IpAddressManager {
4343
"If true, when account has dedicated public ip range(s), once the ips dedicated to the account have been consumed ips will be acquired from the system pool",
4444
true, ConfigKey.Scope.Account);
4545

46+
static final ConfigKey<Boolean> RulesContinueOnError = new ConfigKey<Boolean>("Advanced", Boolean.class, "network.rule.delete.ignoreerror", "true",
47+
"When true, ip address delete (ipassoc) failures are ignored", true);
48+
4649
/**
4750
* Assigns a new public ip address.
4851
*

server/src/com/cloud/network/IpAddressManagerImpl.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
282282
SearchBuilder<IPAddressVO> AssignIpAddressSearch;
283283
SearchBuilder<IPAddressVO> AssignIpAddressFromPodVlanSearch;
284284

285+
static Boolean rulesContinueOnErrFlag = true;
286+
285287
@Override
286288
public boolean configure(String name, Map<String, Object> params) {
287289
// populate providers
@@ -403,7 +405,11 @@ public boolean configure(String name, Map<String, Object> params) {
403405

404406
Network.State.getStateMachine().registerListener(new NetworkStateListener(_configDao));
405407

406-
s_logger.info("Network Manager is configured.");
408+
if (RulesContinueOnError.value() != null) {
409+
rulesContinueOnErrFlag = RulesContinueOnError.value();
410+
}
411+
412+
s_logger.info("IPAddress Manager is configured.");
407413

408414
return true;
409415
}
@@ -601,7 +607,7 @@ public boolean disassociatePublicIpAddress(long addrId, long userId, Account cal
601607
if (ip.getAssociatedWithNetworkId() != null) {
602608
Network network = _networksDao.findById(ip.getAssociatedWithNetworkId());
603609
try {
604-
if (!applyIpAssociations(network, true)) {
610+
if (!applyIpAssociations(network, rulesContinueOnErrFlag)) {
605611
s_logger.warn("Unable to apply ip address associations for " + network);
606612
success = false;
607613
}
@@ -2029,6 +2035,6 @@ public String getConfigComponentName() {
20292035

20302036
@Override
20312037
public ConfigKey<?>[] getConfigKeys() {
2032-
return new ConfigKey<?>[] {UseSystemPublicIps};
2038+
return new ConfigKey<?>[] {UseSystemPublicIps, RulesContinueOnError};
20332039
}
20342040
}

server/src/com/cloud/network/firewall/FirewallManagerImpl.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,16 @@ public class FirewallManagerImpl extends ManagerBase implements FirewallService,
143143
IpAddressManager _ipAddrMgr;
144144

145145
private boolean _elbEnabled = false;
146+
static Boolean rulesContinueOnErrFlag = true;
146147

147148
@Override
148149
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
149150
_name = name;
150151
String elbEnabledString = _configDao.getValue(Config.ElasticLoadBalancerEnabled.key());
151152
_elbEnabled = Boolean.parseBoolean(elbEnabledString);
153+
if (_ipAddrMgr.RulesContinueOnError.value() != null) {
154+
rulesContinueOnErrFlag = _ipAddrMgr.RulesContinueOnError.value();
155+
}
152156
return true;
153157
}
154158

@@ -851,8 +855,12 @@ public boolean revokeFirewallRulesForIp(long ipId, long userId, Account caller)
851855

852856
// now send everything to the backend
853857
List<FirewallRuleVO> rulesToApply = _firewallDao.listByIpAndPurpose(ipId, Purpose.Firewall);
854-
applyFirewallRules(rulesToApply, true, caller);
855-
858+
//apply rules
859+
if (!applyFirewallRules(rulesToApply, rulesContinueOnErrFlag, caller)) {
860+
if (!rulesContinueOnErrFlag) {
861+
return false;
862+
}
863+
}
856864
// Now we check again in case more rules have been inserted.
857865
rules.addAll(_firewallDao.listByIpAndPurposeAndNotRevoked(ipId, Purpose.Firewall));
858866

server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2001,7 +2001,10 @@ protected boolean handleSystemLBIpRelease(LoadBalancerVO lb) {
20012001

20022002
@Override
20032003
public boolean removeAllLoadBalanacersForIp(long ipId, Account caller, long callerUserId) {
2004-
List<FirewallRuleVO> rules = _firewallDao.listByIpAndPurposeAndNotRevoked(ipId, Purpose.LoadBalancing);
2004+
2005+
//Included revoked rules to remove the rules of ips which are in revoke state
2006+
List<FirewallRuleVO> rules = _firewallDao.listByIpAndPurpose(ipId, Purpose.LoadBalancing);
2007+
20052008
if (rules != null) {
20062009
s_logger.debug("Found " + rules.size() + " lb rules to cleanup");
20072010
for (FirewallRule rule : rules) {

server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1845,7 +1845,15 @@ protected void finalizeNetworkRulesForNetwork(final Commands cmds, final DomainR
18451845

18461846
if (_networkModel.isProviderSupportServiceInNetwork(guestNetworkId, Service.StaticNat, provider)) {
18471847
if (ip.isOneToOneNat()) {
1848-
final StaticNatImpl staticNat = new StaticNatImpl(ip.getAccountId(), ip.getDomainId(), guestNetworkId, ip.getId(), ip.getVmIp(), false);
1848+
1849+
boolean revoke = false;
1850+
if (ip.getState() == IpAddress.State.Releasing ) {
1851+
// for ips got struck in releasing state we need to delete the rule not add.
1852+
s_logger.debug("Rule revoke set to true for the ip " + ip.getAddress() +" becasue it is in releasing state");
1853+
revoke = true;
1854+
}
1855+
final StaticNatImpl staticNat = new StaticNatImpl(ip.getAccountId(), ip.getDomainId(), guestNetworkId, ip.getId(), ip.getVmIp(), revoke);
1856+
18491857
staticNats.add(staticNat);
18501858
}
18511859
}

server/src/com/cloud/network/rules/RulesManagerImpl.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ private boolean revokePortForwardingRuleInternal(long ruleId, Account caller, lo
701701
boolean success = false;
702702

703703
if (apply) {
704-
success = applyPortForwardingRules(rule.getSourceIpAddressId(), true, caller);
704+
success = applyPortForwardingRules(rule.getSourceIpAddressId(), _ipAddrMgr.RulesContinueOnError.value(), caller);
705705
} else {
706706
success = true;
707707
}
@@ -736,7 +736,7 @@ private boolean revokeStaticNatRuleInternal(long ruleId, Account caller, long us
736736
boolean success = false;
737737

738738
if (apply) {
739-
success = applyStaticNatRulesForIp(rule.getSourceIpAddressId(), true, caller, true);
739+
success = applyStaticNatRulesForIp(rule.getSourceIpAddressId(), _ipAddrMgr.RulesContinueOnError.value(), caller, true);
740740
} else {
741741
success = true;
742742
}
@@ -769,7 +769,7 @@ public boolean revokePortForwardingRulesForVm(long vmId) {
769769
// apply rules for all ip addresses
770770
for (Long ipId : ipsToReprogram) {
771771
s_logger.debug("Applying port forwarding rules for ip address id=" + ipId + " as a part of vm expunge");
772-
if (!applyPortForwardingRules(ipId, true, _accountMgr.getSystemAccount())) {
772+
if (!applyPortForwardingRules(ipId, _ipAddrMgr.RulesContinueOnError.value(), _accountMgr.getSystemAccount())) {
773773
s_logger.warn("Failed to apply port forwarding rules for ip id=" + ipId);
774774
success = false;
775775
}
@@ -1098,10 +1098,10 @@ public boolean revokeAllPFAndStaticNatRulesForIp(long ipId, long userId, Account
10981098
boolean success = true;
10991099

11001100
// revoke all port forwarding rules
1101-
success = success && applyPortForwardingRules(ipId, true, caller);
1101+
success = success && applyPortForwardingRules(ipId, _ipAddrMgr.RulesContinueOnError.value(), caller);
11021102

11031103
// revoke all all static nat rules
1104-
success = success && applyStaticNatRulesForIp(ipId, true, caller, true);
1104+
success = success && applyStaticNatRulesForIp(ipId, _ipAddrMgr.RulesContinueOnError.value(), caller, true);
11051105

11061106
// revoke static nat for the ip address
11071107
success = success && applyStaticNatForIp(ipId, false, caller, true);
@@ -1144,9 +1144,11 @@ public boolean revokeAllPFStaticNatRulesForNetwork(long networkId, long userId,
11441144
boolean success = true;
11451145
// revoke all PF rules for the network
11461146
success = success && applyPortForwardingRulesForNetwork(networkId, true, caller);
1147+
success = success && applyPortForwardingRulesForNetwork(networkId, _ipAddrMgr.RulesContinueOnError.value(), caller);
11471148

11481149
// revoke all all static nat rules for the network
11491150
success = success && applyStaticNatRulesForNetwork(networkId, true, caller);
1151+
success = success && applyStaticNatRulesForNetwork(networkId, _ipAddrMgr.RulesContinueOnError.value(), caller);
11501152

11511153
// Now we check again in case more rules have been inserted.
11521154
rules.addAll(_portForwardingDao.listByNetworkAndNotRevoked(networkId));

0 commit comments

Comments
 (0)