diff options
author | sarthurdev <965089+sarthurdev@users.noreply.github.com> | 2024-02-13 00:19:30 +0100 |
---|---|---|
committer | sarthurdev <965089+sarthurdev@users.noreply.github.com> | 2024-02-13 02:36:20 +0100 |
commit | c44d24eae276f77c700e961a22c0cd5582416dff (patch) | |
tree | ae1c3ba70f03a8e6f50ddafe1a4ae57e0c6ea4f8 /python | |
parent | 19df28989d72f8006e1defd241ec5cc34660bbec (diff) | |
download | vyos-1x-c44d24eae276f77c700e961a22c0cd5582416dff.tar.gz vyos-1x-c44d24eae276f77c700e961a22c0cd5582416dff.zip |
dhcpv6-server: T5992: Fix op-mode Kea DHCP lease output
Due to Kea's lease file cleanup, the CSV file content is inconsistent. This commit makes changes to use the Kea control socket to fetch current lease information.
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/kea.py | 35 |
1 files changed, 10 insertions, 25 deletions
diff --git a/python/vyos/kea.py b/python/vyos/kea.py index 720bebec3..0a629fcbc 100644 --- a/python/vyos/kea.py +++ b/python/vyos/kea.py @@ -17,8 +17,6 @@ import json import os import socket -from datetime import datetime - from vyos.template import is_ipv6 from vyos.template import isc_static_route from vyos.template import netmask_from_cidr @@ -290,29 +288,6 @@ def kea6_parse_subnet(subnet, config): return out -def kea_parse_leases(lease_path): - contents = read_file(lease_path) - lines = contents.split("\n") - output = [] - - if len(lines) < 2: - return output - - headers = lines[0].split(",") - - for line in lines[1:]: - line_out = dict(zip(headers, line.split(","))) - - lifetime = int(line_out['valid_lifetime']) - expiry = int(line_out['expire']) - - line_out['start_timestamp'] = datetime.utcfromtimestamp(expiry - lifetime) - line_out['expire_timestamp'] = datetime.utcfromtimestamp(expiry) if expiry else None - - output.append(line_out) - - return output - def _ctrl_socket_command(path, command, args=None): if not os.path.exists(path): return None @@ -337,6 +312,16 @@ def _ctrl_socket_command(path, command, args=None): return json.loads(result.decode('utf-8')) +def kea_get_leases(inet): + ctrl_socket = f'/run/kea/dhcp{inet}-ctrl-socket' + + leases = _ctrl_socket_command(ctrl_socket, f'lease{inet}-get-all') + + if not leases or 'result' not in leases or leases['result'] != 0: + return [] + + return leases['arguments']['leases'] + def kea_get_active_config(inet): ctrl_socket = f'/run/kea/dhcp{inet}-ctrl-socket' |