summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-04-05 21:52:52 +0200
committerChristian Poessinger <christian@poessinger.com>2020-04-05 21:52:52 +0200
commit542cdf7b5e162990de91ee045509bec3a8125b2f (patch)
tree3d1ee40b490866efe14c9ca5ea080143f4a9093f /src
parent166b86163824b1ae43aed78487d5cd2dba1a07d6 (diff)
downloadvyos-1x-542cdf7b5e162990de91ee045509bec3a8125b2f.tar.gz
vyos-1x-542cdf7b5e162990de91ee045509bec3a8125b2f.zip
vrf: T2230: move inlined templates to dedicated files
Diffstat (limited to 'src')
-rwxr-xr-xsrc/conf_mode/vrf.py23
1 files changed, 8 insertions, 15 deletions
diff --git a/src/conf_mode/vrf.py b/src/conf_mode/vrf.py
index 53ee13bec..8cf4b72ae 100755
--- a/src/conf_mode/vrf.py
+++ b/src/conf_mode/vrf.py
@@ -15,34 +15,22 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
-import jinja2
from sys import exit
from copy import deepcopy
+from jinja2 import FileSystemLoader, Environment
from json import loads
from subprocess import check_output, CalledProcessError
from vyos.config import Config
from vyos.configdict import list_diff
+from vyos.defaults import directories as vyos_data_dir
from vyos.ifconfig import Interface
from vyos.util import read_file
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,
@@ -194,7 +182,12 @@ def verify(vrf_config):
return None
def generate(vrf_config):
- tmpl = jinja2.Template(config_tmpl)
+ # Prepare Jinja2 template loader from files
+ tmpl_path = os.path.join(vyos_data_dir['data'], 'templates', 'vrf')
+ fs_loader = FileSystemLoader(tmpl_path)
+ env = Environment(loader=fs_loader)
+
+ tmpl = env.get_template('vrf.conf.tmpl')
config_text = tmpl.render(vrf_config)
with open(config_file, 'w') as f:
f.write(config_text)