From 39dfcfb5077a4024c454f9cd127fc1f65529f591 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Wed, 4 Mar 2020 20:55:04 +0100 Subject: vrf: T31: create iproute2 table to name mapping reference --- src/conf_mode/vrf.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/conf_mode/vrf.py') diff --git a/src/conf_mode/vrf.py b/src/conf_mode/vrf.py index e31285dde..91d8f8432 100755 --- a/src/conf_mode/vrf.py +++ b/src/conf_mode/vrf.py @@ -15,6 +15,7 @@ # along with this program. If not, see . import os +import jinja2 from sys import exit from copy import deepcopy @@ -23,6 +24,21 @@ from vyos.config import Config from vyos.configdict import list_diff from vyos import ConfigError +config_file = r'/etc/iproute2/rt_tables.d/vyos-vrf.conf' + +# Please be careful if you edit the template. +config_tmpl = """ +### Autogenerated by vrf.py ### +# +# Routing table ID to name mapping reference + +# id vrf name comment +{% for vrf in vrf_add -%} +{{ "%-10s" | format(vrf.table) }} {{ "%-16s" | format(vrf.name) }} # {{ vrf.description }} +{% endfor -%} + +""" + default_config_data = { 'bind_to_all': 0, 'deleted': False, @@ -141,6 +157,11 @@ def verify(vrf_config): return None def generate(vrf_config): + tmpl = jinja2.Template(config_tmpl) + config_text = tmpl.render(vrf_config) + with open(config_file, 'w') as f: + f.write(config_text) + return None def apply(vrf_config): -- cgit v1.2.3