@ -180,6 +180,16 @@ except ImportError:
from distutils . version import StrictVersion
from distutils . version import StrictVersion
ROUTER_INTERFACE_OWNERS = set ( [
' network:router_interface ' ,
' network:router_interface_distributed ' ,
' network:ha_router_replicated_interface '
] )
def _router_internal_interfaces ( cloud , router ) :
for port in cloud . list_router_interfaces ( router , ' internal ' ) :
if port [ ' device_owner ' ] in ROUTER_INTERFACE_OWNERS :
yield port
def _needs_update ( cloud , module , router , network , internal_subnet_ids ) :
def _needs_update ( cloud , module , router , network , internal_subnet_ids ) :
""" Decide if the given router needs an update.
""" Decide if the given router needs an update.
@ -221,7 +231,7 @@ def _needs_update(cloud, module, router, network, internal_subnet_ids):
# check internal interfaces
# check internal interfaces
if module . params [ ' interfaces ' ] :
if module . params [ ' interfaces ' ] :
existing_subnet_ids = [ ]
existing_subnet_ids = [ ]
for port in cloud. list_router_interfaces ( router , ' internal ' ) :
for port in _router_internal_interfaces( cloud , router ) :
if ' fixed_ips ' in port :
if ' fixed_ips ' in port :
for fixed_ip in port [ ' fixed_ips ' ] :
for fixed_ip in port [ ' fixed_ips ' ] :
existing_subnet_ids . append ( fixed_ip [ ' subnet_id ' ] )
existing_subnet_ids . append ( fixed_ip [ ' subnet_id ' ] )
@ -377,7 +387,7 @@ def main():
# just detach all existing internal interfaces and attach the new.
# just detach all existing internal interfaces and attach the new.
elif internal_ids :
elif internal_ids :
router = updated_router
router = updated_router
ports = cloud. list_router_interfaces ( router , ' internal ' )
ports = _router_internal_interfaces( cloud , router )
for port in ports :
for port in ports :
cloud . remove_router_interface ( router , port_id = port [ ' id ' ] )
cloud . remove_router_interface ( router , port_id = port [ ' id ' ] )
for internal_subnet_id in internal_ids :
for internal_subnet_id in internal_ids :
@ -394,7 +404,7 @@ def main():
else :
else :
# We need to detach all internal interfaces on a router before
# We need to detach all internal interfaces on a router before
# we will be allowed to delete it.
# we will be allowed to delete it.
ports = cloud. list_router_interfaces ( router , ' internal ' )
ports = _router_internal_interfaces( cloud , router )
router_id = router [ ' id ' ]
router_id = router [ ' id ' ]
for port in ports :
for port in ports :
cloud . remove_router_interface ( router , port_id = port [ ' id ' ] )
cloud . remove_router_interface ( router , port_id = port [ ' id ' ] )