summaryrefslogtreecommitdiff
path: root/src/conf_mode/interfaces-wireless.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-04-12 21:07:53 +0200
committerGitHub <noreply@github.com>2020-04-12 21:07:53 +0200
commit8978c7eaf4b1a89712242c8626a217024aae2f2b (patch)
tree1248cd48ca5571d5d2098574ab932692767b5d2b /src/conf_mode/interfaces-wireless.py
parentad489280ba7f4511016883c24a6d0b06b6659df8 (diff)
parent1fbaa2c59d0c0f43acad10db99d66b92fc520888 (diff)
downloadvyos-1x-8978c7eaf4b1a89712242c8626a217024aae2f2b.tar.gz
vyos-1x-8978c7eaf4b1a89712242c8626a217024aae2f2b.zip
Merge pull request #332 from thomas-mangin/T2230
template: T2230: use render to generate templates
Diffstat (limited to 'src/conf_mode/interfaces-wireless.py')
-rwxr-xr-xsrc/conf_mode/interfaces-wireless.py21
1 files changed, 6 insertions, 15 deletions
diff --git a/src/conf_mode/interfaces-wireless.py b/src/conf_mode/interfaces-wireless.py
index 66fdd2d93..10aec3dcd 100755
--- a/src/conf_mode/interfaces-wireless.py
+++ b/src/conf_mode/interfaces-wireless.py
@@ -19,18 +19,18 @@ from sys import exit
from re import findall
from copy import deepcopy
-from jinja2 import FileSystemLoader, Environment
from netifaces import interfaces
from netaddr import EUI, mac_unix_expanded
from vyos.config import Config
from vyos.configdict import list_diff, vlan_to_dict
-from vyos.defaults import directories as vyos_data_dir
from vyos.ifconfig import WiFiIf
from vyos.ifconfig_vlan import apply_vlan_config, verify_vlan_config
from vyos.util import chown, is_bridge_member, call
from vyos import ConfigError
+from vyos.template import render
+
default_config_data = {
'address': [],
@@ -600,11 +600,6 @@ def verify(wifi):
return None
def generate(wifi):
- # Prepare Jinja2 template loader from files
- tmpl_path = os.path.join(vyos_data_dir["data"], "templates", "wifi")
- fs_loader = FileSystemLoader(tmpl_path)
- env = Environment(loader=fs_loader)
-
interface = wifi['intf']
# always stop hostapd service first before reconfiguring it
@@ -646,16 +641,12 @@ def generate(wifi):
# render appropriate new config files depending on access-point or station mode
if wifi['op_mode'] == 'ap':
- tmpl = env.get_template('hostapd.conf.tmpl')
- config_text = tmpl.render(wifi)
- with open(get_conf_file('hostapd', interface), 'w') as f:
- f.write(config_text)
+ conf = get_conf_file('hostapd', interface)
+ render(conf, 'wifi/hostapd.conf.tmpl', wifi)
elif wifi['op_mode'] == 'station':
- tmpl = env.get_template('wpa_supplicant.conf.tmpl')
- config_text = tmpl.render(wifi)
- with open(get_conf_file('wpa_supplicant', interface), 'w') as f:
- f.write(config_text)
+ conf = get_conf_file('wpa_supplicant', interface)
+ render(conf, 'wifi/wpa_supplicant.conf.tmpl', wifi)
return None