summaryrefslogtreecommitdiff
path: root/python/vyos/ifconfig/dhcp.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-08-03 12:56:13 +0200
committerChristian Poessinger <christian@poessinger.com>2020-08-03 12:56:13 +0200
commit84331764a81d7e31c5c4dd5466f347054283d377 (patch)
treef971fb39fb09a34a5022f85ff300804bd83db6d9 /python/vyos/ifconfig/dhcp.py
parent091efc96bc0fbeea7c7bf1e8e234c72bc8df801b (diff)
downloadvyos-1x-84331764a81d7e31c5c4dd5466f347054283d377.tar.gz
vyos-1x-84331764a81d7e31c5c4dd5466f347054283d377.zip
ifconfig: T2740: pass config dict to DHCP class for IPv6
This removes additional code paths as we can instatly work with the input dict the same was as it was done for PPPoE. This fixes the entire DHCPv6-PD support on non PPPoE interfaces as this was lost in translation while processing T2653.
Diffstat (limited to 'python/vyos/ifconfig/dhcp.py')
-rw-r--r--python/vyos/ifconfig/dhcp.py36
1 files changed, 14 insertions, 22 deletions
diff --git a/python/vyos/ifconfig/dhcp.py b/python/vyos/ifconfig/dhcp.py
index a8b9a2a87..bd37970a2 100644
--- a/python/vyos/ifconfig/dhcp.py
+++ b/python/vyos/ifconfig/dhcp.py
@@ -15,6 +15,7 @@
import os
+from vyos.configverify import verify_dhcpv6
from vyos.dicts import FixedDict
from vyos.ifconfig.control import Control
from vyos.template import render
@@ -82,39 +83,31 @@ class _DHCPv4 (Control):
class _DHCPv6 (Control):
def __init__(self, ifname):
super().__init__()
- self.options = FixedDict(**{
- 'ifname': ifname,
- 'dhcpv6_prm_only': False,
- 'dhcpv6_temporary': False,
- 'dhcpv6_pd_interfaces': [],
- 'dhcpv6_pd_length': ''
- })
- self._conf_file = f'/run/dhcp6c/dhcp6c.{ifname}.conf'
+ self.options = {'ifname' : ifname}
+ self._config = f'/run/dhcp6c/dhcp6c.{ifname}.conf'
def set(self):
"""
- Configure interface as DHCPv6 client. The dhclient binary is automatically
- started in background!
+ Configure interface as DHCPv6 client. The client is automatically
+ started in background when address is configured as DHCP.
Example:
-
>>> from vyos.ifconfig import Interface
>>> j = Interface('eth0')
>>> j.dhcp.v6.set()
"""
- # better save then sorry .. should be checked in interface script
- # but if you missed it we are safe!
- if self.options['dhcpv6_prm_only'] and self.options['dhcpv6_temporary']:
- raise Exception(
- 'DHCPv6 temporary and parameters-only options are mutually exclusive!')
+ # better save then sorry .. should be checked in interface script but if you
+ # missed it we are safe!
+ verify_dhcpv6(self.options)
- render(self._conf_file, 'dhcp-client/ipv6.tmpl', self.options, trim_blocks=True)
- return self._cmd('systemctl restart dhcp6c@{ifname}.service'.format(**self.options))
+ render(self._config, 'dhcp-client/ipv6.tmpl', self.options, trim_blocks=True)
+ return self._cmd('systemctl restart dhcp6c@{ifname}.service'.format(
+ **self.options))
def delete(self):
"""
- De-configure interface as DHCPv6 clinet. All auto generated files like
+ De-configure interface as DHCPv6 client. All auto generated files like
pid, config and lease will be removed.
Example:
@@ -126,9 +119,8 @@ class _DHCPv6 (Control):
self._cmd('systemctl stop dhcp6c@{ifname}.service'.format(**self.options))
# cleanup old config files
- if os.path.isfile(self._conf_file):
- os.remove(self._conf_file)
-
+ if os.path.isfile(self._config):
+ os.remove(self._config)
class DHCP(object):
def __init__(self, ifname):