Create a port for new router interface if gateway IP is already assigned
Change-Id: Ia463fd4674473b00ef86f2beaaaa1de538ffc394
This commit is contained in:
parent
f27e5f0b41
commit
e59840857e
|
@ -175,22 +175,49 @@ def ensure_router_interface(subnet: neutron.SubnetIdType,
|
||||||
router = get_router_id()
|
router = get_router_id()
|
||||||
router_id = neutron.get_router_id(router)
|
router_id = neutron.get_router_id(router)
|
||||||
subnet_id = neutron.get_subnet_id(subnet)
|
subnet_id = neutron.get_subnet_id(subnet)
|
||||||
|
client = neutron.neutron_client(client)
|
||||||
try:
|
try:
|
||||||
return neutron.find_port(fixed_ips=f"subnet_id={subnet_id}",
|
port = neutron.find_port(fixed_ips=f"subnet_id={subnet_id}",
|
||||||
device_id=router_id)
|
device_id=router_id,
|
||||||
|
client=client)
|
||||||
except tobiko.ObjectNotFound:
|
except tobiko.ObjectNotFound:
|
||||||
pass
|
pass
|
||||||
|
else:
|
||||||
|
port_dump = json.dumps(port, indent=4, sort_keys=True)
|
||||||
|
LOG.debug(f'Router interface already exist:\n{port_dump}')
|
||||||
|
return port
|
||||||
|
|
||||||
|
subnet = neutron.ensure_subnet_gateway(subnet=subnet,
|
||||||
|
client=client)
|
||||||
|
gateway_ip = subnet['gateway_ip']
|
||||||
|
try:
|
||||||
|
port = neutron.find_port(fixed_ips=[f'ip_address={gateway_ip}'],
|
||||||
|
client=client)
|
||||||
|
except tobiko.ObjectNotFound:
|
||||||
|
LOG.info(f"Add router interface: subnet={subnet_id}")
|
||||||
|
interface = neutron.add_router_interface(router=router,
|
||||||
|
subnet=subnet,
|
||||||
|
add_cleanup=False,
|
||||||
|
client=client)
|
||||||
|
port = neutron.find_port(fixed_ips=f"subnet_id={subnet_id}",
|
||||||
|
device_id=router_id)
|
||||||
|
else:
|
||||||
|
port_dump = json.dumps(port, indent=4, sort_keys=True)
|
||||||
|
LOG.debug(f'Port with gateway IP already exists:\n{port_dump}')
|
||||||
|
port = neutron.create_port(client=client,
|
||||||
|
network=subnet['network_id'],
|
||||||
|
add_cleanup=False)
|
||||||
|
interface = neutron.add_router_interface(router=router,
|
||||||
|
port=port,
|
||||||
|
add_cleanup=False,
|
||||||
|
client=client)
|
||||||
|
|
||||||
LOG.debug(f"Add router interface: subnet={subnet_id}")
|
|
||||||
subnet = neutron.ensure_subnet_gateway(subnet=subnet)
|
|
||||||
interface = neutron.add_router_interface(router=router,
|
|
||||||
subnet=subnet,
|
|
||||||
add_cleanup=False,
|
|
||||||
client=client)
|
|
||||||
interface_dump = json.dumps(interface, sort_keys=True, indent=4)
|
interface_dump = json.dumps(interface, sort_keys=True, indent=4)
|
||||||
LOG.info(f"Added router interface:\n{interface_dump}")
|
port_dump = json.dumps(port, indent=4, sort_keys=True)
|
||||||
return neutron.find_port(fixed_ips=f"subnet_id={subnet_id}",
|
LOG.info("Router interface added:\n"
|
||||||
device_id=router_id)
|
f"{interface_dump}\n"
|
||||||
|
f"{port_dump}\n")
|
||||||
|
return port
|
||||||
|
|
||||||
|
|
||||||
@neutron.skip_if_missing_networking_extensions('port-security')
|
@neutron.skip_if_missing_networking_extensions('port-security')
|
||||||
|
|
Loading…
Reference in New Issue