summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/vyos/ifconfig/dhcp.py36
-rw-r--r--python/vyos/ifconfig/interface.py49
2 files changed, 34 insertions, 51 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):
diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py
index d477153e8..f5e43e172 100644
--- a/python/vyos/ifconfig/interface.py
+++ b/python/vyos/ifconfig/interface.py
@@ -822,6 +822,22 @@ class Interface(Control):
value = '2' if 'disable_link_detect' in config else '1'
self.set_link_detect(value)
+ # DHCP options
+ if 'dhcp_options' in config:
+ dhcp_options = config.get('dhcp_options')
+ if 'client_id' in dhcp_options:
+ self.dhcp.v4.options['client_id'] = dhcp_options.get('client_id')
+
+ if 'host_name' in dhcp_options:
+ self.dhcp.v4.options['hostname'] = dhcp_options.get('host_name')
+
+ if 'vendor_class_id' in dhcp_options:
+ self.dhcp.v4.options['vendor_class_id'] = dhcp_options.get('vendor_class_id')
+
+ # DHCPv6 options
+ if 'dhcpv6_options' in config:
+ self.dhcp.v6.options = config
+
# Configure assigned interface IP addresses. No longer
# configured addresses will be removed first
new_addr = config.get('address', [])
@@ -849,35 +865,6 @@ class Interface(Control):
# checked before
self.set_vrf(config.get('vrf', ''))
- # DHCP options
- if 'dhcp_options' in config:
- dhcp_options = config.get('dhcp_options')
- if 'client_id' in dhcp_options:
- self.dhcp.v4.options['client_id'] = dhcp_options.get('client_id')
-
- if 'host_name' in dhcp_options:
- self.dhcp.v4.options['hostname'] = dhcp_options.get('host_name')
-
- if 'vendor_class_id' in dhcp_options:
- self.dhcp.v4.options['vendor_class_id'] = dhcp_options.get('vendor_class_id')
-
- # DHCPv6 options
- if 'dhcpv6_options' in config:
- dhcpv6_options = config.get('dhcpv6_options')
- if 'parameters_only' in dhcpv6_options:
- self.dhcp.v6.options['dhcpv6_prm_only'] = True
-
- if 'temporary' in dhcpv6_options:
- self.dhcp.v6.options['dhcpv6_temporary'] = True
-
- if 'prefix_delegation' in dhcpv6_options:
- prefix_delegation = dhcpv6_options.get('prefix_delegation')
- if 'length' in prefix_delegation:
- self.dhcp.v6.options['dhcpv6_pd_length'] = prefix_delegation.get('length')
-
- if 'interface' in prefix_delegation:
- self.dhcp.v6.options['dhcpv6_pd_interfaces'] = prefix_delegation.get('interface')
-
# Configure ARP cache timeout in milliseconds - has default value
tmp = jmespath.search('ip.arp_cache_timeout', config)
value = tmp if (tmp != None) else '30'
@@ -982,9 +969,11 @@ class Interface(Control):
self.del_vlan(vif_s_id)
# create/update 802.1ad (Q-in-Q VLANs)
+ ifname = config['ifname']
for vif_s_id, vif_s in config.get('vif_s', {}).items():
tmp=get_ethertype(vif_s.get('ethertype', '0x88A8'))
s_vlan = self.add_vlan(vif_s_id, ethertype=tmp)
+ vif_s['ifname'] = f'{ifname}.{vif_s_id}'
s_vlan.update(vif_s)
# remove no longer required client VLAN (vif-c)
@@ -994,6 +983,7 @@ class Interface(Control):
# create/update client VLAN (vif-c) interface
for vif_c_id, vif_c in vif_s.get('vif_c', {}).items():
c_vlan = s_vlan.add_vlan(vif_c_id)
+ vif_c['ifname'] = f'{ifname}.{vif_s_id}.{vif_c_id}'
c_vlan.update(vif_c)
# remove no longer required 802.1q VLAN interfaces
@@ -1003,4 +993,5 @@ class Interface(Control):
# create/update 802.1q VLAN interfaces
for vif_id, vif in config.get('vif', {}).items():
vlan = self.add_vlan(vif_id)
+ vif['ifname'] = f'{ifname}.{vif_id}'
vlan.update(vif)