From a8fdd1f42d0b46b06487dcdeca792d8db67b4558 Mon Sep 17 00:00:00 2001 From: Taoyu Li Date: Wed, 22 Mar 2017 20:13:55 -0700 Subject: [PATCH] [oneimage] Enable forcing mgmt route through minigraph (#424) --- files/image_config/interfaces/interfaces.j2 | 6 ++++++ src/sonic-config-engine/minigraph.py | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/files/image_config/interfaces/interfaces.j2 b/files/image_config/interfaces/interfaces.j2 index 8cca143ed6..c6156dab8b 100644 --- a/files/image_config/interfaces/interfaces.j2 +++ b/files/image_config/interfaces/interfaces.j2 @@ -28,9 +28,15 @@ iface eth0 inet static # management port up rules up ip route add default via {{ minigraph_mgmt_interface['gwaddr'] }} dev eth0 table default up ip rule add from {{ minigraph_mgmt_interface['addr'] }}/32 table default +{% for prefix in forced_mgmt_routes %} + up ip route add {{ prefix }} via {{ minigraph_mgmt_interface['gwaddr'] }} dev eth0 +{% endfor %} # management port down rules down ip route delete default via {{ minigraph_mgmt_interface['gwaddr'] }} dev eth0 table default down ip rule delete from {{ minigraph_mgmt_interface['addr'] }}/32 table default +{% for prefix in forced_mgmt_routes %} + down ip route delete {{ prefix }} via {{ minigraph_mgmt_interface['gwaddr'] }} dev eth0 +{% endfor %} {# TODO: COPP policy type rules #} {% else %} iface eth0 inet dhcp diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index 144593557a..20c5aeb5b5 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -301,6 +301,7 @@ def parse_meta(meta, hname): syslog_servers = [] dhcp_servers = [] ntp_servers = [] + mgmt_routes = [] device_metas = meta.find(str(QName(ns, "Devices"))) for device in device_metas.findall(str(QName(ns1, "DeviceMetadata"))): if device.find(str(QName(ns1, "Name"))).text == hname: @@ -315,7 +316,9 @@ def parse_meta(meta, hname): ntp_servers = value_group elif name == "SyslogResources": syslog_servers = value_group - return syslog_servers, dhcp_servers, ntp_servers + elif name == "ForcedMgmtRoutes": + mgmt_routes = value_group + return syslog_servers, dhcp_servers, ntp_servers, mgmt_routes def get_console_info(devices, dev, port): for k, v in devices.items(): @@ -397,6 +400,7 @@ def parse_xml(filename, platform=None, port_config_file=None): syslog_servers = [] dhcp_servers = [] ntp_servers = [] + mgmt_routes = [] hwsku_qn = QName(ns, "HwSku") hostname_qn = QName(ns, "Hostname") @@ -421,7 +425,7 @@ def parse_xml(filename, platform=None, port_config_file=None): elif child.tag == str(QName(ns, "UngDec")): (u_neighbors, u_devices, _, _, _, _) = parse_png(child, hostname) elif child.tag == str(QName(ns, "MetadataDeclaration")): - (syslog_servers, dhcp_servers, ntp_servers) = parse_meta(child, hostname) + (syslog_servers, dhcp_servers, ntp_servers, mgmt_routes) = parse_meta(child, hostname) Tree = lambda: defaultdict(Tree) @@ -455,6 +459,7 @@ def parse_xml(filename, platform=None, port_config_file=None): results['syslog_servers'] = syslog_servers results['dhcp_servers'] = dhcp_servers results['ntp_servers'] = ntp_servers + results['forced_mgmt_routes'] = mgmt_routes results['alias_map'] = alias_map_list return results