summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2024-02-13 17:36:39 +0100
committerGitHub <noreply@github.com>2024-02-13 17:36:39 +0100
commitbae2b7c506223d59cc136123444b22e10bea6c0b (patch)
treeeb8762be0fb824daa96f385f265f99907c03dff0 /python
parent83bf14e34a986ba35904f3889341310f85ae88c4 (diff)
parentdbfaa47b0036339e28ae8fd57c8007612e1b38f3 (diff)
downloadvyos-1x-bae2b7c506223d59cc136123444b22e10bea6c0b.tar.gz
vyos-1x-bae2b7c506223d59cc136123444b22e10bea6c0b.zip
Merge pull request #2998 from sarthurdev/T5992
dhcpv6-server: T5992: Fix op-mode DHCP lease output + updates
Diffstat (limited to 'python')
-rw-r--r--python/vyos/kea.py35
1 files changed, 10 insertions, 25 deletions
diff --git a/python/vyos/kea.py b/python/vyos/kea.py
index 7365c1f02..894ac9e9a 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
@@ -293,29 +291,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
@@ -340,6 +315,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'