summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/templates/dhcp-client/ipv4.tmpl17
-rw-r--r--data/templates/dhcp-client/ipv6.tmpl4
-rw-r--r--python/vyos/ifconfig/dhcp.py40
3 files changed, 24 insertions, 37 deletions
diff --git a/data/templates/dhcp-client/ipv4.tmpl b/data/templates/dhcp-client/ipv4.tmpl
new file mode 100644
index 000000000..43f273077
--- /dev/null
+++ b/data/templates/dhcp-client/ipv4.tmpl
@@ -0,0 +1,17 @@
+# 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;
+}
diff --git a/data/templates/dhcp-client/ipv6.tmpl b/data/templates/dhcp-client/ipv6.tmpl
new file mode 100644
index 000000000..83db40c5f
--- /dev/null
+++ b/data/templates/dhcp-client/ipv6.tmpl
@@ -0,0 +1,4 @@
+# generated by ifconfig.py
+interface "{{ ifname }}" {
+ request routers, domain-name-servers, domain-name;
+}
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)