diff options
author | Christian Poessinger <christian@poessinger.com> | 2023-01-06 08:14:44 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2023-01-06 08:14:44 +0100 |
commit | e32ce63b52eff0255d602b475d90cd97d3b282c1 (patch) | |
tree | 4a7f6006374265f40bc3bac4774885ba716dd82d /src/conf_mode/protocols_static.py | |
parent | 5e474ec9c6c7c6fff2a8f1597c16443ec582d4dd (diff) | |
download | vyos-1x-e32ce63b52eff0255d602b475d90cd97d3b282c1.tar.gz vyos-1x-e32ce63b52eff0255d602b475d90cd97d3b282c1.zip |
static: T4883: fix KeyError: 'table'
Commit dafb0da2 ("static: T4883: add a description field for routing tables")
added an iproute2 description table but lacked checking if the key exists.
This has been fixed and also converted to Jinja2 to keep the "common" style
inside the routing protocols. It might feel overengineered indeed.
Diffstat (limited to 'src/conf_mode/protocols_static.py')
-rwxr-xr-x | src/conf_mode/protocols_static.py | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/conf_mode/protocols_static.py b/src/conf_mode/protocols_static.py index cbbc476a7..3e5ebb805 100755 --- a/src/conf_mode/protocols_static.py +++ b/src/conf_mode/protocols_static.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (C) 2021 VyOS maintainers and contributors +# Copyright (C) 2021-2023 VyOS maintainers and contributors # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 or later as @@ -25,12 +25,15 @@ from vyos.configdict import get_dhcp_interfaces from vyos.configdict import get_pppoe_interfaces from vyos.configverify import verify_common_route_maps from vyos.configverify import verify_vrf +from vyos.template import render from vyos.template import render_to_string from vyos import ConfigError from vyos import frr from vyos import airbag airbag.enable() +config_file = '/etc/iproute2/rt_tables.d/vyos-static.conf' + def get_config(config=None): if config: conf = config @@ -94,19 +97,13 @@ def verify(static): def generate(static): if not static: return None + + # Put routing table names in /etc/iproute2/rt_tables + render(config_file, 'iproute2/static.conf.j2', static) static['new_frr_config'] = render_to_string('frr/staticd.frr.j2', static) return None def apply(static): - ## Put routing table names in /etc/iproute2/rt_tables - with open("/etc/iproute2/rt_tables.d/vyos.conf", 'w') as f: - print("# Generated by VyOS (protocols_static.py), do not edit by hand", file=f) - for t in static['table']: - if 'description' in static['table'][t]: - print(f"{t}\t{static['table'][t]['description']}", file=f) - - ## Inject routes into FRR - static_daemon = 'staticd' zebra_daemon = 'zebra' |