mirror of https://github.com/apache/cloudstack.git
bug 12276: public IP's should be associated with a network service provider depending on the network rules for which IP is used for
This commit is contained in:
parent
62b571a528
commit
4f058feef2
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.PublicIpAddress;
|
||||
import com.cloud.network.lb.LoadBalancingRule;
|
||||
|
||||
public interface LoadBalancingServiceProvider extends NetworkElement {
|
||||
|
|
@ -15,4 +16,13 @@ public interface LoadBalancingServiceProvider extends NetworkElement {
|
|||
* @throws ResourceUnavailableException
|
||||
*/
|
||||
boolean applyLBRules(Network network, List<LoadBalancingRule> rules) throws ResourceUnavailableException;
|
||||
|
||||
/**
|
||||
* Apply ip addresses to this network service provider
|
||||
* @param network
|
||||
* @param ipAddress
|
||||
* @return
|
||||
* @throws ResourceUnavailableException
|
||||
*/
|
||||
boolean applyLoadBalancerIp(Network network, List<? extends PublicIpAddress> ipAddress) throws ResourceUnavailableException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.PublicIpAddress;
|
||||
import com.cloud.network.rules.PortForwardingRule;
|
||||
|
||||
public interface PortForwardingServiceProvider extends NetworkElement {
|
||||
|
|
@ -15,4 +16,13 @@ public interface PortForwardingServiceProvider extends NetworkElement {
|
|||
* @throws ResourceUnavailableException
|
||||
*/
|
||||
boolean applyPFRules(Network network, List<PortForwardingRule> rules) throws ResourceUnavailableException;
|
||||
|
||||
/**
|
||||
* Apply ip addresses to this network service provider
|
||||
* @param network
|
||||
* @param ipAddress
|
||||
* @return
|
||||
* @throws ResourceUnavailableException
|
||||
*/
|
||||
boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress) throws ResourceUnavailableException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,19 @@
|
|||
package com.cloud.network.element;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.PublicIpAddress;
|
||||
|
||||
public interface SourceNatServiceProvider extends NetworkElement {
|
||||
|
||||
/**
|
||||
* Apply ip addresses to this network
|
||||
* @param network
|
||||
* @param ipAddress
|
||||
* @return
|
||||
* @throws ResourceUnavailableException
|
||||
*/
|
||||
boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress) throws ResourceUnavailableException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.PublicIpAddress;
|
||||
import com.cloud.network.rules.StaticNat;
|
||||
|
||||
public interface StaticNatServiceProvider extends NetworkElement {
|
||||
|
|
@ -15,4 +16,13 @@ public interface StaticNatServiceProvider extends NetworkElement {
|
|||
* @throws ResourceUnavailableException
|
||||
*/
|
||||
boolean applyStaticNats(Network config, List<? extends StaticNat> rules) throws ResourceUnavailableException;
|
||||
|
||||
/**
|
||||
* Apply ip addresses to this network service provider
|
||||
* @param network
|
||||
* @param ipAddress
|
||||
* @return
|
||||
* @throws ResourceUnavailableException
|
||||
*/
|
||||
boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress) throws ResourceUnavailableException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -601,8 +601,79 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
return success;
|
||||
}
|
||||
|
||||
protected boolean applyProviderIpAssociations(Network network, Purpose purpose, boolean continueOnError, List<? extends FirewallRule> rules) throws ResourceUnavailableException {
|
||||
boolean success = true;
|
||||
|
||||
List<PublicIp> publicIps = new ArrayList<PublicIp>();
|
||||
for (FirewallRule rule : rules) {
|
||||
IPAddressVO lbIp = _ipAddressDao.findById(rule.getSourceIpAddressId());
|
||||
PublicIp publicIp = new PublicIp(lbIp, _vlanDao.findById(lbIp.getVlanId()), NetUtils.createSequenceBasedMacAddress(lbIp.getMacAddress()));
|
||||
publicIps.add(publicIp);
|
||||
}
|
||||
|
||||
for (NetworkElement ne : _networkElements) {
|
||||
try {
|
||||
boolean handled;
|
||||
switch (purpose) {
|
||||
case LoadBalancing:
|
||||
if (!(ne instanceof LoadBalancingServiceProvider)) {
|
||||
continue;
|
||||
}
|
||||
LoadBalancingServiceProvider lbProvider = (LoadBalancingServiceProvider) ne;
|
||||
s_logger.trace("Asking " + ne + " to apply ip associations for " + purpose.toString() + " purpose");
|
||||
handled = lbProvider.applyLoadBalancerIp(network, publicIps);
|
||||
break;
|
||||
|
||||
case PortForwarding:
|
||||
if (!(ne instanceof PortForwardingServiceProvider)) {
|
||||
continue;
|
||||
}
|
||||
PortForwardingServiceProvider pfProvider = (PortForwardingServiceProvider) ne;
|
||||
s_logger.trace("Asking " + ne + " to apply ip associations for " + purpose.toString() + " purpose");
|
||||
handled = pfProvider.applyIps(network, publicIps);
|
||||
break;
|
||||
|
||||
case StaticNat:
|
||||
case Firewall:
|
||||
if (!(ne instanceof FirewallServiceProvider)) {
|
||||
continue;
|
||||
}
|
||||
s_logger.trace("Asking " + ne + " to apply ip associations for " + purpose.toString() + " purpose");
|
||||
FirewallServiceProvider fwProvider = (FirewallServiceProvider) ne;
|
||||
handled = fwProvider.applyIps(network, publicIps);
|
||||
break;
|
||||
|
||||
default:
|
||||
s_logger.debug("Unable to handle IP association for purpose: " + purpose.toString());
|
||||
handled = false;
|
||||
}
|
||||
s_logger.debug("Network Rules for network " + network.getId() + " were " + (handled ? "" : " not") + " handled by " + ne.getName());
|
||||
} catch (ResourceUnavailableException e) {
|
||||
success = false;
|
||||
if (!continueOnError) {
|
||||
throw e;
|
||||
} else {
|
||||
s_logger.debug("Resource is not available: " + ne.getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
protected boolean applyIpAssociations(Network network, boolean continueOnError, List<PublicIp> publicIps) throws ResourceUnavailableException {
|
||||
boolean success = true;
|
||||
List<PublicIp> srcNatpublicIps = new ArrayList<PublicIp>();
|
||||
|
||||
// apply IP only for source NAT public IP at this point. Depending on the network service for which
|
||||
// public IP will be used do IP Association to respective network service provider before apply rules
|
||||
if (publicIps != null && !publicIps.isEmpty()) {
|
||||
for (PublicIp ip : publicIps) {
|
||||
if (ip.isSourceNat()) {
|
||||
srcNatpublicIps.add(ip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (NetworkElement element : _networkElements) {
|
||||
try {
|
||||
if (!(element instanceof FirewallServiceProvider)) {
|
||||
|
|
@ -610,7 +681,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
}
|
||||
FirewallServiceProvider e = (FirewallServiceProvider)element;
|
||||
s_logger.trace("Asking " + element + " to apply ip associations");
|
||||
e.applyIps(network, publicIps);
|
||||
e.applyIps(network, srcNatpublicIps);
|
||||
} catch (ResourceUnavailableException e) {
|
||||
success = false;
|
||||
if (!continueOnError) {
|
||||
|
|
@ -2583,6 +2654,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
boolean success = true;
|
||||
Network network = _networksDao.findById(rules.get(0).getNetworkId());
|
||||
Purpose purpose = rules.get(0).getPurpose();
|
||||
|
||||
// associate the IP with corresponding network service provider
|
||||
applyProviderIpAssociations(network, purpose, continueOnError, rules);
|
||||
|
||||
for (NetworkElement ne : _networkElements) {
|
||||
try {
|
||||
boolean handled;
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import com.cloud.network.Network.Service;
|
|||
import com.cloud.network.NetworkManager;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.network.PhysicalNetworkServiceProvider;
|
||||
import com.cloud.network.PublicIpAddress;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.network.lb.ElasticLoadBalancerManager;
|
||||
import com.cloud.network.lb.LoadBalancingRule;
|
||||
|
|
@ -179,4 +180,10 @@ public class ElasticLoadBalancerElement extends AdapterBase implements LoadBalan
|
|||
public boolean verifyServicesCombination(List<String> services) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyLoadBalancerIp(Network network, List<? extends PublicIpAddress> ipAddress) throws ResourceUnavailableException {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ import com.cloud.network.NetworkManager;
|
|||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.network.PhysicalNetworkServiceProvider;
|
||||
import com.cloud.network.PhysicalNetworkVO;
|
||||
import com.cloud.network.PublicIpAddress;
|
||||
import com.cloud.network.dao.ExternalLoadBalancerDeviceDao;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.network.dao.NetworkExternalLoadBalancerDao;
|
||||
|
|
@ -440,4 +441,10 @@ public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceMan
|
|||
public boolean verifyServicesCombination(List<String> services) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyLoadBalancerIp(Network network, List<? extends PublicIpAddress> ipAddress) throws ResourceUnavailableException {
|
||||
// return true, as IP will be associated as part of LB rule configuration
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -175,16 +175,6 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddresses) throws ResourceUnavailableException {
|
||||
if (!canHandle(network)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return applyIps(network, ipAddresses);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean applyFWRules(Network config, List<? extends FirewallRule> rules) throws ResourceUnavailableException {
|
||||
if (!canHandle(config)) {
|
||||
|
|
@ -505,4 +495,10 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
|
|||
public boolean verifyServicesCombination(List<String> services) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress) throws ResourceUnavailableException {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -64,6 +64,7 @@ import com.cloud.network.NetworkVO;
|
|||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.network.PhysicalNetworkServiceProvider;
|
||||
import com.cloud.network.PhysicalNetworkVO;
|
||||
import com.cloud.network.PublicIpAddress;
|
||||
import com.cloud.network.dao.ExternalLoadBalancerDeviceDao;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.network.dao.NetworkExternalLoadBalancerDao;
|
||||
|
|
@ -465,4 +466,10 @@ public class NetscalerExternalLoadBalancerElement extends ExternalLoadBalancerDe
|
|||
public boolean verifyServicesCombination(List<String> services) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyLoadBalancerIp(Network network, List<? extends PublicIpAddress> ipAddress) throws ResourceUnavailableException {
|
||||
// return true, as IP will be associated as part of LB rule configuration
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -270,6 +270,21 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyLoadBalancerIp(Network network, List<? extends PublicIpAddress> ipAddress) throws ResourceUnavailableException {
|
||||
if (canHandle(network, Service.Lb)) {
|
||||
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
|
||||
if (routers == null || routers.isEmpty()) {
|
||||
s_logger.debug("Virtual router element doesn't need to associate load balancer ip addresses on the backend; virtual router doesn't exist in the network " + network.getId());
|
||||
return true;
|
||||
}
|
||||
|
||||
return _routerMgr.associateIP(network, ipAddress, routers);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Provider getProvider() {
|
||||
return Provider.VirtualRouter;
|
||||
|
|
@ -644,4 +659,5 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue