summaryrefslogtreecommitdiff
path: root/src/conf_mode/interfaces-openvpn.py
diff options
context:
space:
mode:
authorThomas Mangin <thomas.mangin@exa.net.uk>2020-04-11 19:32:25 +0100
committerThomas Mangin <thomas.mangin@exa.net.uk>2020-04-12 20:05:13 +0100
commit1fbaa2c59d0c0f43acad10db99d66b92fc520888 (patch)
tree1248cd48ca5571d5d2098574ab932692767b5d2b /src/conf_mode/interfaces-openvpn.py
parentad489280ba7f4511016883c24a6d0b06b6659df8 (diff)
downloadvyos-1x-1fbaa2c59d0c0f43acad10db99d66b92fc520888.tar.gz
vyos-1x-1fbaa2c59d0c0f43acad10db99d66b92fc520888.zip
template: T2230: use render to generate templates
convert all call to jinja to use template.render
Diffstat (limited to 'src/conf_mode/interfaces-openvpn.py')
-rwxr-xr-xsrc/conf_mode/interfaces-openvpn.py21
1 files changed, 5 insertions, 16 deletions
diff --git a/src/conf_mode/interfaces-openvpn.py b/src/conf_mode/interfaces-openvpn.py
index 974aeea69..85945ba58 100755
--- a/src/conf_mode/interfaces-openvpn.py
+++ b/src/conf_mode/interfaces-openvpn.py
@@ -17,7 +17,6 @@
import os
import re
-from jinja2 import FileSystemLoader, Environment
from copy import deepcopy
from sys import exit
from ipaddress import ip_address,ip_network,IPv4Interface
@@ -26,11 +25,12 @@ from time import sleep
from shutil import rmtree
from vyos.config import Config
-from vyos.defaults import directories as vyos_data_dir
from vyos.ifconfig import VTunIf
from vyos.util import call, is_bridge_member, chown, chmod_600, chmod_755
from vyos.validate import is_addr_assigned
from vyos import ConfigError
+from vyos.template import render
+
user = 'openvpn'
group = 'openvpn'
@@ -653,11 +653,6 @@ def generate(openvpn):
if openvpn['deleted'] or openvpn['disable']:
return None
- # Prepare Jinja2 template loader from files
- tmpl_path = os.path.join(vyos_data_dir['data'], 'templates', 'openvpn')
- fs_loader = FileSystemLoader(tmpl_path)
- env = Environment(loader=fs_loader)
-
interface = openvpn['intf']
directory = os.path.dirname(get_config_name(interface))
@@ -697,19 +692,13 @@ def generate(openvpn):
# Generate client specific configuration
for client in openvpn['client']:
client_file = os.path.join(ccd_dir, client['name'])
- tmpl = env.get_template('client.conf.tmpl')
- client_text = tmpl.render(client)
- with open(client_file, 'w') as f:
- f.write(client_text)
+ render(client_file, 'openvpn/client.conf.tmpl', client)
chown(client_file, user, group)
- tmpl = env.get_template('server.conf.tmpl')
- config_text = tmpl.render(openvpn)
# we need to support quoting of raw parameters from OpenVPN CLI
# see https://phabricator.vyos.net/T1632
- config_text = config_text.replace("&quot;",'"')
- with open(get_config_name(interface), 'w') as f:
- f.write(config_text)
+ render(get_config_name(interface), 'openvpn/server.conf.tmpl', openvpn,
+ formater=lambda _: _.replace("&quot;", '"'))
chown(get_config_name(interface), user, group)
# Fixup file permissions