summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/vyos/configdict.py5
-rw-r--r--python/vyos/ifconfig.py56
2 files changed, 49 insertions, 12 deletions
diff --git a/python/vyos/configdict.py b/python/vyos/configdict.py
index 1c9cf6897..1022b88de 100644
--- a/python/vyos/configdict.py
+++ b/python/vyos/configdict.py
@@ -112,6 +112,7 @@ def vlan_to_dict(conf):
'description': '',
'dhcp_client_id': '',
'dhcp_hostname': '',
+ 'dhcp_vendor_class_id': '',
'dhcpv6_prm_only': False,
'dhcpv6_temporary': False,
'disable': False,
@@ -145,6 +146,10 @@ def vlan_to_dict(conf):
if conf.exists('dhcp-options host-name'):
vlan['dhcp_hostname'] = conf.return_value('dhcp-options host-name')
+ # DHCP client vendor identifier
+ if conf.exists('dhcp-options vendor-class-id'):
+ vlan['dhcp_vendor_class_id'] = conf.return_value('dhcp-options vendor-class-id')
+
# DHCPv6 only acquire config parameters, no address
if conf.exists('dhcpv6-options parameters-only'):
vlan['dhcpv6_prm_only'] = conf.return_value('dhcpv6-options parameters-only')
diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py
index 4ac605b54..23e66c089 100644
--- a/python/vyos/ifconfig.py
+++ b/python/vyos/ifconfig.py
@@ -23,13 +23,26 @@ from netifaces import ifaddresses, AF_INET, AF_INET6
from subprocess import Popen, PIPE, STDOUT
from time import sleep
+dhclient_base = r'/var/lib/dhcp/dhclient_'
dhcp_cfg = """
# generated by ifconfig.py
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
+timeout 60;
+retry 300;
+
interface "{{ intf }}" {
send host-name "{{ hostname }}";
- request subnet-mask, broadcast-address, routers, domain-name-servers, rfc3442-classless-static-routes, domain-name, interface-mtu;
+ {% 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;
}
+
"""
dhcpv6_cfg = """
@@ -37,10 +50,8 @@ dhcpv6_cfg = """
interface "{{ intf }}" {
request routers, domain-name-servers, domain-name;
}
-"""
-
-dhclient_base = r'/var/lib/dhcp/dhclient_'
+"""
class Interface:
def __init__(self, ifname, type=None):
@@ -78,6 +89,14 @@ class Interface:
self._dhcpv6_pid_file = dhclient_base + self._ifname + '.v6pid'
self._dhcpv6_lease_file = dhclient_base + self._ifname + '.v6leases'
+ # DHCP options
+ self._dhcp_options = {
+ 'intf' : self._ifname,
+ 'hostname' : '',
+ 'client_id' : '',
+ 'vendor_class_id' : ''
+ }
+
def _debug_msg(self, msg):
if os.path.isfile('/tmp/vyos.ifconfig.debug'):
print('DEBUG/{:<6} {}'.format(self._ifname, msg))
@@ -449,6 +468,21 @@ class Interface:
cmd = 'ip addr del "{}" dev "{}"'.format(addr, self._ifname)
return self._cmd(cmd)
+
+ def get_dhcp_options(self):
+ """
+ Return dictionary with supported DHCP options.
+ Dictionary should be altered and send back via set_dhcp_options()
+ so those options are applied when DHCP is run.
+ """
+ return self._dhcp_options
+
+ def set_dhcp_options(self, options):
+ """
+ Store new DHCP options used by next run of DHCP client.
+ """
+ self._dhcp_options = options
+
# replace dhcpv4/v6 with systemd.networkd?
def _set_dhcp(self):
"""
@@ -461,15 +495,13 @@ class Interface:
>>> j = Interface('eth0')
>>> j.set_dhcp()
"""
- dhcp = {
- 'hostname': 'vyos',
- 'intf': self._ifname
- }
- # read configured system hostname.
- # maybe change to vyos hostd client ???
- with open('/etc/hostname', 'r') as f:
- dhcp['hostname'] = f.read().rstrip('\n')
+ dhcp = self.get_dhcp_options()
+ if not dhcp['hostname']:
+ # read configured system hostname.
+ # maybe change to vyos hostd client ???
+ with open('/etc/hostname', 'r') as f:
+ dhcp['hostname'] = f.read().rstrip('\n')
# render DHCP configuration
tmpl = jinja2.Template(dhcp_cfg)