Reuse the router passed as config if available

It allows forcing the router and the external network because
the current process can easily detect a wrong external network
or router.

It detects if the router name set in config already exits. If yes,
it will be selected and the external network will be its gateway.
If the router is not connected to an external network, the process
will be unchanged. Then a new router will be created (same name).

It doesn't change the purpose of reuse_network_name (provider
networks).

Change-Id: I50069118fa7020900bea3dd579db18d087d3e47f
Signed-off-by: Cédric Ollivier <ollivier.cedric@gmail.com>
This commit is contained in:
Cédric Ollivier 2018-08-03 09:15:58 +02:00 committed by Cédric Ollivier
parent 9c016e3f96
commit 99b261cccc

View File

@ -57,10 +57,24 @@ class Network(object):
raise vmtp.VmtpException("Unable to find the network to be reused.")
return
else:
##########################################
# If the user defined router is available,
# then select it and its gateway
##########################################
routers = neutron_client.list_routers(
name=config.router_name)['routers']
if routers and routers[0].get("external_gateway_info"):
self.ext_router = routers[0]
ext_net = self.ext_router["external_gateway_info"][
'network_id']
self.ext_net = neutron_client.show_network(ext_net)['network']
LOG.info('Using external router: %s', self.ext_router['name'])
##############################################
# If a user provided ext_net_name is not available,
# then find the first network that is external
##############################################
if not self.ext_net:
for network in self.networks:
if network['router:external']:
try:
@ -81,13 +95,15 @@ class Network(object):
LOG.info("Using external network: %s.", self.ext_net['name'])
# Find or create the router to the external network
ext_net_id = self.ext_net['id']
if not self.ext_router:
routers = neutron_client.list_routers()['routers']
for router in routers:
external_gw_info = router['external_gateway_info']
if external_gw_info:
if external_gw_info['network_id'] == ext_net_id:
self.ext_router = router
LOG.info('Found external router: %s', self.ext_router['name'])
LOG.info('Found external router: %s',
self.ext_router['name'])
break
# create a new external router if none found and a name was given