diff options
author | Oyvind Bakksjo <bakksjo@yahoo-inc.com> | 2016-06-24 14:22:40 +0200 |
---|---|---|
committer | Oyvind Bakksjo <bakksjo@yahoo-inc.com> | 2016-06-27 12:44:11 +0200 |
commit | 4da1d9e6e00cded5f84d485d3f6beddec07dd49b (patch) | |
tree | 29a6b482cfd24243a9e068046f4942166d09d0b6 | |
parent | df204c194a89bf3a48ab99f188248df8752f01bb (diff) |
Factor out function to fetch default route for network namespace.
-rwxr-xr-x | node-admin/scripts/configure-container-networking.py | 61 |
1 files changed, 32 insertions, 29 deletions
diff --git a/node-admin/scripts/configure-container-networking.py b/node-admin/scripts/configure-container-networking.py index c3d2f04d734..fc22d93944d 100755 --- a/node-admin/scripts/configure-container-networking.py +++ b/node-admin/scripts/configure-container-networking.py @@ -210,6 +210,37 @@ def set_ip_address(net_namespace, interface_index, ip_address, network_prefix_le if e.code == 17: # File exists, i.e. address is already added pass +def get_default_route(net_namespace): + # route format: { + # 'family': 2, + # 'dst_len': 0, + # 'proto': 3, + # 'tos': 0, + # 'event': 'RTM_NEWROUTE', + # 'header': { + # 'pid': 43, + # 'length': 52, + # 'flags': 2, + # 'error': None, + # 'type': 24, + # 'sequence_number': 255 + # }, + # 'flags': 0, + # 'attrs': [ + # ['RTA_TABLE', 254], + # ['RTA_GATEWAY', '172.17.42.1'], + # ['RTA_OIF', 18] + # ], + # 'table': 254, + # 'src_len': 0, + # 'type': 1, + # 'scope': 0 + # } + default_routes = net_namespace.get_default_routes(family = AF_INET) + if len(default_routes) != 1: + raise RuntimeError("Couldn't find single default route: " + str(default_routes)) + return default_routes[0] + flag_local_mode = "--local" local_mode = flag_local_mode in sys.argv @@ -305,35 +336,7 @@ elif vm_mode: else: # Set up default route/gateway in container. - # route format: { - # 'family': 2, - # 'dst_len': 0, - # 'proto': 3, - # 'tos': 0, - # 'event': 'RTM_NEWROUTE', - # 'header': { - # 'pid': 43, - # 'length': 52, - # 'flags': 2, - # 'error': None, - # 'type': 24, - # 'sequence_number': 255 - # }, - # 'flags': 0, - # 'attrs': [ - # ['RTA_TABLE', 254], - # ['RTA_GATEWAY', '172.17.42.1'], - # ['RTA_OIF', 18] - # ], - # 'table': 254, - # 'src_len': 0, - # 'type': 1, - # 'scope': 0 - # } - host_default_routes = host_ns.get_default_routes(family = AF_INET) - if len(host_default_routes) != 1: - raise RuntimeError("Couldn't find default route: " + str(host_default_routes)) - default_route = host_default_routes[0] + default_route = get_default_route(net_namespace=host_ns) host_default_route_device_index = get_attribute(default_route, 'RTA_OIF') host_default_gateway = get_attribute(default_route, 'RTA_GATEWAY') |