NSXv3: Validate LB router gateway

Add one more validation to check if LB subnet is connected to a
router that already setup gateway on external network.

Change-Id: Ic8e9227534a78f18a57ed18cfebe9b400907a98a
This commit is contained in:
Tong Liu 2017-11-29 16:37:28 -08:00
parent 0334b7d5c7
commit 78aae2093d
2 changed files with 12 additions and 9 deletions

View File

@ -45,7 +45,9 @@ def get_router_from_network(context, plugin, subnet_id):
'network_id': [network_id]}
ports = plugin.get_ports(context, filters=port_filters)
if ports:
return ports[0]['device_id']
router = plugin.get_router(context, ports[0]['device_id'])
if router.get('external_gateway_info'):
return True
def get_lb_router_id(context, plugin, lb):
@ -78,8 +80,9 @@ def validate_lb_subnet(context, plugin, subnet_id):
'''Validate LB subnet before creating loadbalancer on it.
To create a loadbalancer, the network has to be either an external
network or private network that connects to a tenant router. It will
throw exception if the network doesn't meet this requirement.
network or private network that connects to a tenant router. The
tenant router needs to connect to gateway. It will throw
exception if the network doesn't meet this requirement.
:param context: context
:param plugin: core plugin
@ -87,9 +90,9 @@ def validate_lb_subnet(context, plugin, subnet_id):
:return: True if subnet meet requirement, otherwise return False
'''
network = get_network_from_subnet(context, plugin, subnet_id)
router_id = get_router_from_network(
valid_router = get_router_from_network(
context, plugin, subnet_id)
if network.get('router:external') or router_id:
if network.get('router:external') or valid_router:
return True
else:
return False

View File

@ -47,10 +47,10 @@ class EdgeLoadBalancerManager(base_mgr.Nsxv3LoadbalancerBaseManager):
lb.vip_subnet_id):
self.lbv2_driver.load_balancer.successful_completion(context, lb)
else:
msg = _('Cannot create lb on subnet %(sub)s for '
'loadbalancer %(lb)s as it does not connect '
'to router') % {'sub': lb.vip_subnet_id,
'lb': lb.id}
msg = (_('Cannot create lb on subnet %(sub)s for '
'loadbalancer %(lb)s. The subnet needs to connect a '
'router which is already set gateway.') %
{'sub': lb.vip_subnet_id, 'lb': lb.id})
raise n_exc.BadRequest(resource='lbaas-subnet', msg=msg)
@log_helpers.log_method_call