summaryrefslogtreecommitdiff
path: root/python/vyos/ifconfig
diff options
context:
space:
mode:
authorThomas Mangin <thomas.mangin@exa.net.uk>2020-04-11 12:58:52 +0100
committerThomas Mangin <thomas.mangin@exa.net.uk>2020-04-11 13:12:55 +0100
commite12a0ce922b67354ecd8e53414cda6b8b3a424fb (patch)
treeede57ba64a9d3a04b6523f7d139a255a0ec9d033 /python/vyos/ifconfig
parentef2e8f4d721a6486db90c0f395f595ca897614b8 (diff)
downloadvyos-1x-e12a0ce922b67354ecd8e53414cda6b8b3a424fb.tar.gz
vyos-1x-e12a0ce922b67354ecd8e53414cda6b8b3a424fb.zip
dhcp: T2230: use external template files
Diffstat (limited to 'python/vyos/ifconfig')
-rw-r--r--python/vyos/ifconfig/dhcp.py40
1 files changed, 3 insertions, 37 deletions
diff --git a/python/vyos/ifconfig/dhcp.py b/python/vyos/ifconfig/dhcp.py
index 5b0a0bf6a..d4ff9c2cd 100644
--- a/python/vyos/ifconfig/dhcp.py
+++ b/python/vyos/ifconfig/dhcp.py
@@ -14,10 +14,10 @@
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
import os
-import jinja2
from vyos.dicts import FixedDict
from vyos.ifconfig.control import Control
+from vyos.template import render
class _DHCP (Control):
@@ -34,26 +34,6 @@ class _DHCP (Control):
}
class _DHCPv4 (_DHCP):
- template = """\
- # generated by ifconfig.py
- option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
- timeout 60;
- retry 300;
-
- interface "{{ ifname }}" {
- send host-name "{{ hostname }}";
- {% if client_id -%}
- send dhcp-client-identifier "{{ client_id }}";
- {% endif -%}
- {% if vendor_class_id -%}
- send vendor-class-identifier "{{ vendor_class_id }}";
- {% endif -%}
- request subnet-mask, broadcast-address, routers, domain-name-servers,
- rfc3442-classless-static-routes, domain-name, interface-mtu;
- require subnet-mask;
- }
- """.replace(' ', '')
-
def __init__(self, ifname):
super().__init__(ifname, '')
self.options = FixedDict(**{
@@ -82,10 +62,7 @@ class _DHCPv4 (_DHCP):
with open('/etc/hostname', 'r') as f:
self.options['hostname'] = f.read().rstrip('\n')
- # render DHCP configuration
- tmpl = jinja2.Template(self.template)
- with open(self.file['conf'], 'w') as f:
- f.write(tmpl.render(self.options))
+ render(self.file['conf'], 'dhcp-client/ipv4.tmpl' ,self.options)
cmd = 'start-stop-daemon'
cmd += ' --start'
@@ -137,14 +114,6 @@ class _DHCPv4 (_DHCP):
class _DHCPv6 (_DHCP):
- template = """\
- # generated by ifconfig.py
- interface "{{ ifname }}" {
- request routers, domain-name-servers, domain-name;
- }
-
- """.replace(' ', '')
-
def __init__(self, ifname):
super().__init__(ifname, 'v6')
self.options = FixedDict(**{
@@ -174,10 +143,7 @@ class _DHCPv6 (_DHCP):
raise Exception(
'DHCPv6 temporary and parameters-only options are mutually exclusive!')
- # render DHCP configuration
- tmpl = jinja2.Template(self.template)
- with open(self.file['conf'], 'w') as f:
- f.write(tmpl.render(self.options))
+ render(self.file['conf'], 'dhcp-client/ipv6.tmpl', self.options)
# no longer accept router announcements on this interface
self._write_sysfs(self.file['accept_ra'], 0)