Skip to content

Commit 6deeb7d

Browse files
Alena ProkharchykAlena Prokharchyk
authored andcommitted
Firewall service is enabled in default elb/eip network offering
Also added more handling for error cases scenarios
1 parent 0e8104c commit 6deeb7d

6 files changed

Lines changed: 47 additions & 29 deletions

File tree

api/src/com/cloud/api/commands/CreateIpForwardingRuleCmd.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import com.cloud.network.IpAddress;
4040
import com.cloud.network.rules.FirewallRule;
4141
import com.cloud.network.rules.StaticNatRule;
42-
import com.cloud.network.rules.FirewallRule.FirewallRuleType;
4342
import com.cloud.user.Account;
4443
import com.cloud.user.UserContext;
4544

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,6 @@ void checkCapabilityForProvider(Set<Provider> providers, Service service,
282282
IpAddress assignElasticIp(long networkId, Account owner,
283283
boolean forElasticLb, boolean forElasticIp)
284284
throws InsufficientAddressCapacityException;
285+
286+
boolean handleElasticIpRelease(IpAddress ip);
285287
}

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1935,8 +1935,9 @@ public boolean disassociateIpAddress(long ipAddressId) {
19351935
UserVm vm = null;
19361936
if (vmId != null) {
19371937
vm = _userVmDao.findById(vmId);
1938+
return _rulesMgr.enableElasticIpAndStaticNatForVm(vm, true);
19381939
}
1939-
return _rulesMgr.enableElasticIpAndStaticNatForVm(vm, true);
1940+
return true;
19401941
} else {
19411942
s_logger.warn("Failed to release public ip address id=" + ipAddressId);
19421943
return false;
@@ -5879,4 +5880,24 @@ public IpAddress assignElasticIp(long networkId, Account owner, boolean forElast
58795880
return ip;
58805881
}
58815882

5883+
@Override
5884+
public boolean handleElasticIpRelease(IpAddress ip) {
5885+
boolean success = true;
5886+
Long networkId = ip.getAssociatedWithNetworkId();
5887+
if (networkId != null) {
5888+
Network guestNetwork = getNetwork(networkId);
5889+
NetworkOffering offering = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId());
5890+
if (offering.getElasticIp()) {
5891+
UserContext ctx = UserContext.current();
5892+
if (!releasePublicIpAddress(ip.getId(), ctx.getCallerUserId(), ctx.getCaller())) {
5893+
s_logger.warn("Unable to release elastic ip address id=" + ip.getId());
5894+
success = false;
5895+
} else {
5896+
s_logger.warn("Successfully released elastic ip address id=" + ip.getId());
5897+
}
5898+
}
5899+
}
5900+
return success;
5901+
}
5902+
58825903
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,11 +633,21 @@ public LoadBalancer createLoadBalancerRule(CreateLoadBalancerRuleCmd lb, boolea
633633

634634
LoadBalancer result = _elbMgr.handleCreateLoadBalancerRule(lb, lbOwner, lb.getNetworkId());
635635
if (result == null){
636+
IpAddress ip = null;
636637
if (off.getElasticLb()) {
637-
IpAddress ip = _networkMgr.assignElasticIp(lb.getNetworkId(), lbOwner, true, false);
638+
ip = _networkMgr.assignElasticIp(lb.getNetworkId(), lbOwner, true, false);
638639
lb.setSourceIpAddressId(ip.getId());
639640
}
640-
result = createLoadBalancer(lb, openFirewall);
641+
try {
642+
result = createLoadBalancer(lb, openFirewall);
643+
} catch (Exception ex) {
644+
s_logger.warn("Failed to create load balancer due to ", ex);
645+
} finally {
646+
if (result == null && ip != null) {
647+
s_logger.debug("Releasing elastic IP address " + ip + " as corresponding lb rule failed to create");
648+
_networkMgr.handleElasticIpRelease(ip);
649+
}
650+
}
641651
}
642652

643653
if (result == null){

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

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ public boolean enableStaticNat(long ipId, long vmId) throws NetworkRuleConflictE
338338
// Check permissions
339339
checkIpAndUserVm(ipAddress, vm, caller);
340340

341-
// Verify that the ip is associated with the network and firewallService is supported for the network
341+
// Verify that the ip is associated with the network and static nat service is supported for the network
342342
Long networkId = ipAddress.getAssociatedWithNetworkId();
343343
if (networkId == null) {
344344
throw new InvalidParameterValueException("Unable to enable static nat for the ipAddress id=" + ipId + " as ip is not associated with any network");
@@ -351,8 +351,8 @@ public boolean enableStaticNat(long ipId, long vmId) throws NetworkRuleConflictE
351351
}
352352

353353
Network network = _networkMgr.getNetwork(networkId);
354-
if (!_networkMgr.areServicesSupportedInNetwork(network.getId(), Service.Firewall)) {
355-
throw new InvalidParameterValueException("Unable to create static nat rule; Firewall service is not supported in network id=" + networkId);
354+
if (!_networkMgr.areServicesSupportedInNetwork(network.getId(), Service.StaticNat)) {
355+
throw new InvalidParameterValueException("Unable to create static nat rule; StaticNat service is not supported in network id=" + networkId);
356356
}
357357

358358
// Verify ip address parameter
@@ -1032,7 +1032,7 @@ public boolean disableStaticNat(long ipId) throws ResourceUnavailableException {
10321032
ipAddress.setOneToOneNat(false);
10331033
ipAddress.setAssociatedWithVmId(null);
10341034
_ipAddressDao.update(ipAddress.getId(), ipAddress);
1035-
if (!handleElasticIpRelease(ipAddress)) {
1035+
if (!_networkMgr.handleElasticIpRelease(ipAddress)) {
10361036
s_logger.warn("Failed to release elastic ip address " + ipAddress);
10371037
return false;
10381038
}
@@ -1143,10 +1143,15 @@ public boolean enableElasticIpAndStaticNatForVm(UserVm vm, boolean stopOnError)
11431143
return false;
11441144
}
11451145
s_logger.debug("Allocated elastic ip " + ip + ", now enabling static nat on it for vm " + vm);
1146-
success = success && enableStaticNat(ip.getId(), vm.getId());
1146+
try {
1147+
enableStaticNat(ip.getId(), vm.getId());
1148+
} catch (Exception ex) {
1149+
s_logger.warn("Failed to enable static nat as a part of enabling elasticIp and staticNat for vm " + vm + " in guest network " + guestNetwork + " due to exception ", ex);
1150+
success = false;
1151+
}
11471152
if (!success) {
11481153
s_logger.warn("Failed to enable static nat on elastic ip " + ip + " for the vm " + vm + ", releasing the ip...");
1149-
handleElasticIpRelease(ip);
1154+
_networkMgr.handleElasticIpRelease(ip);
11501155
} else {
11511156
s_logger.warn("Succesfully enabled static nat on elastic ip " + ip + " for the vm " + vm);
11521157
}
@@ -1163,22 +1168,4 @@ public boolean enableElasticIpAndStaticNatForVm(UserVm vm, boolean stopOnError)
11631168
return success;
11641169
}
11651170

1166-
protected boolean handleElasticIpRelease(IpAddress ip) {
1167-
boolean success = true;
1168-
Long networkId = ip.getAssociatedWithNetworkId();
1169-
if (networkId != null) {
1170-
Network guestNetwork = _networkMgr.getNetwork(networkId);
1171-
NetworkOffering offering = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId());
1172-
if (offering.getElasticIp()) {
1173-
UserContext ctx = UserContext.current();
1174-
if (!_networkMgr.releasePublicIpAddress(ip.getId(), ctx.getCallerUserId(), ctx.getCaller())) {
1175-
s_logger.warn("Unable to release elastic ip address id=" + ip.getId());
1176-
success = false;
1177-
} else {
1178-
s_logger.warn("Successfully released elastic ip address id=" + ip.getId());
1179-
}
1180-
}
1181-
}
1182-
return success;
1183-
}
11841171
}

server/src/com/cloud/server/ConfigurationServerImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,6 @@ protected void createDefaultNetworkOfferings() {
870870
netscalerServiceProviders.put(Service.Dns, Provider.VirtualRouter);
871871
netscalerServiceProviders.put(Service.UserData, Provider.VirtualRouter);
872872
netscalerServiceProviders.put(Service.SecurityGroup, Provider.SecurityGroupProvider);
873-
netscalerServiceProviders.put(Service.Firewall, Provider.Netscaler);
874873
netscalerServiceProviders.put(Service.StaticNat, Provider.Netscaler);
875874
netscalerServiceProviders.put(Service.Lb, Provider.Netscaler);
876875

0 commit comments

Comments
 (0)