summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/templates/vrf/vrf.conf.tmpl8
-rwxr-xr-xsrc/conf_mode/vrf.py23
2 files changed, 16 insertions, 15 deletions
diff --git a/data/templates/vrf/vrf.conf.tmpl b/data/templates/vrf/vrf.conf.tmpl
new file mode 100644
index 000000000..761b0bb6f
--- /dev/null
+++ b/data/templates/vrf/vrf.conf.tmpl
@@ -0,0 +1,8 @@
+### 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 -%}
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)