summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2024-01-13 20:12:33 +0100
committerGitHub <noreply@github.com>2024-01-13 20:12:33 +0100
commit9753fafbfed02a3b6ebe7b6ddf51783c5dcbcf62 (patch)
tree929c8b42867462edad25b8028bac07b78c89b6fb /python
parentfef091bd6dc5c3cdfae47e9adb86f610a75a8a4d (diff)
parent2d4db25386fcefd301868a4daa39d5578cbac779 (diff)
downloadvyos-1x-9753fafbfed02a3b6ebe7b6ddf51783c5dcbcf62.tar.gz
vyos-1x-9753fafbfed02a3b6ebe7b6ddf51783c5dcbcf62.zip
Merge pull request #2817 from sarthurdev/kea6-options
dhcpv6: T3316: Extend scope of DHCP options, bugfixes
Diffstat (limited to 'python')
-rw-r--r--python/vyos/kea.py43
-rw-r--r--python/vyos/template.py7
2 files changed, 23 insertions, 27 deletions
diff --git a/python/vyos/kea.py b/python/vyos/kea.py
index aa4fb7ae5..fb5afc2ce 100644
--- a/python/vyos/kea.py
+++ b/python/vyos/kea.py
@@ -175,16 +175,6 @@ def kea_parse_subnet(subnet, config):
def kea6_parse_options(config):
options = []
- if 'common_options' in config:
- common_opt = config['common_options']
-
- for node, option_name in kea6_options.items():
- if node not in common_opt:
- continue
-
- value = ", ".join(common_opt[node]) if isinstance(common_opt[node], list) else common_opt[node]
- options.append({'name': option_name, 'data': value})
-
for node, option_name in kea6_options.items():
if node not in config:
continue
@@ -218,20 +208,27 @@ def kea6_parse_options(config):
def kea6_parse_subnet(subnet, config):
out = {'subnet': subnet, 'id': int(config['subnet_id'])}
- options = kea6_parse_options(config)
- if 'address_range' in config:
- addr_range = config['address_range']
+ if 'option' in config:
+ out['option-data'] = kea6_parse_options(config['option'])
+
+ if 'range' in config:
pools = []
+ for num, range_config in config['range'].items():
+ pool = {}
- if 'prefix' in addr_range:
- for prefix in addr_range['prefix']:
- pools.append({'pool': prefix})
+ if 'prefix' in range_config:
+ pool['pool'] = range_config['prefix']
- if 'start' in addr_range:
- for start, range_conf in addr_range['start'].items():
- stop = range_conf['stop']
- pools.append({'pool': f'{start} - {stop}'})
+ if 'start' in range_config:
+ start = range_config['start']
+ stop = range_config['stop']
+ pool['pool'] = f'{start} - {stop}'
+
+ if 'option' in range_config:
+ pool['option-data'] = kea6_parse_options(range_config['option'])
+
+ pools.append(pool)
out['pools'] = pools
@@ -278,13 +275,13 @@ def kea6_parse_subnet(subnet, config):
if 'ipv6_prefix' in host_config:
reservation['prefixes'] = [ host_config['ipv6_prefix'] ]
+ if 'option' in host_config:
+ reservation['option-data'] = kea6_parse_options(host_config['option'])
+
reservations.append(reservation)
out['reservations'] = reservations
- if options:
- out['option-data'] = options
-
return out
def kea_parse_leases(lease_path):
diff --git a/python/vyos/template.py b/python/vyos/template.py
index 1368f1f61..456239568 100644
--- a/python/vyos/template.py
+++ b/python/vyos/template.py
@@ -894,7 +894,9 @@ def kea6_shared_network_json(shared_networks):
'name': name,
'subnet6': []
}
- options = kea6_parse_options(config)
+
+ if 'common_options' in config:
+ network['option-data'] = kea6_parse_options(config['common_options'])
if 'interface' in config:
network['interface'] = config['interface']
@@ -903,9 +905,6 @@ def kea6_shared_network_json(shared_networks):
for subnet, subnet_config in config['subnet'].items():
network['subnet6'].append(kea6_parse_subnet(subnet, subnet_config))
- if options:
- network['option-data'] = options
-
out.append(network)
return dumps(out, indent=4)