summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorIndrajit Raychaudhuri <irc@indrajit.com>2025-01-22 01:42:33 -0600
committerIndrajit Raychaudhuri <irc@indrajit.com>2025-01-26 12:31:31 -0600
commite8e05f87e5c23eb59d7895ff50e90f3d3e60e2f1 (patch)
tree60c5c571d6529c47a82e28835d7807d578aa3225 /python
parent529c24a9d550b30ba7fabcbae3a5bc0d5d35c647 (diff)
downloadvyos-1x-e8e05f87e5c23eb59d7895ff50e90f3d3e60e2f1.tar.gz
vyos-1x-e8e05f87e5c23eb59d7895ff50e90f3d3e60e2f1.zip
T6998: Remove vestigial helper and reformat
Diffstat (limited to 'python')
-rw-r--r--python/vyos/kea.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/python/vyos/kea.py b/python/vyos/kea.py
index 8b3628db1..baac75eda 100644
--- a/python/vyos/kea.py
+++ b/python/vyos/kea.py
@@ -474,10 +474,11 @@ def kea_get_server_leases(config, inet, pools=[], state=[], origin=None) -> list
data = []
for lease in leases:
lifetime = lease['valid-lft']
- expiry = lease['cltt'] + lifetime
+ start = lease['cltt']
+ expiry = start + lifetime
- lease['start_timestamp'] = datetime.fromtimestamp(lease['cltt'], timezone.utc)
- lease['expire_timestamp'] = (
+ lease['start_time'] = datetime.fromtimestamp(start, timezone.utc)
+ lease['expire_time'] = (
datetime.fromtimestamp(expiry, timezone.utc) if expiry else None
)
@@ -491,7 +492,7 @@ def kea_get_server_leases(config, inet, pools=[], state=[], origin=None) -> list
else '-'
)
data_lease['end'] = (
- lease['expire_timestamp'].timestamp() if lease['expire_timestamp'] else None
+ lease['expire_time'].timestamp() if lease['expire_time'] else None
)
data_lease['origin'] = 'local' # TODO: Determine remote in HA
# remove trailing dot in 'hostname' to ensure consistency for `vyos-hostsd-client`
@@ -499,10 +500,10 @@ def kea_get_server_leases(config, inet, pools=[], state=[], origin=None) -> list
if inet == '4':
data_lease['mac'] = lease['hw-address']
- data_lease['start'] = lease['start_timestamp'].timestamp()
+ data_lease['start'] = lease['start_time'].timestamp()
if inet == '6':
- data_lease['last_communication'] = lease['start_timestamp'].timestamp()
+ data_lease['last_communication'] = lease['start_time'].timestamp()
data_lease['duid'] = _format_hex_string(lease['duid'])
data_lease['type'] = lease['type']
@@ -512,11 +513,11 @@ def kea_get_server_leases(config, inet, pools=[], state=[], origin=None) -> list
data_lease['remaining'] = '-'
- if lease['valid-lft'] > 0:
- if lease['expire_timestamp'] > datetime.now(timezone.utc):
- # substraction gives us a timedelta object which can't be formatted with strftime
- # so we use str(), split gets rid of the microseconds
- data_lease['remaining'] = str(lease['expire_timestamp'] - datetime.now(timezone.utc)).split('.')[0]
+ now = datetime.now(timezone.utc)
+ if lease['valid-lft'] > 0 and lease['expire_time'] > now:
+ # substraction gives us a timedelta object which can't be formatted
+ # with strftime so we use str(), split gets rid of the microseconds
+ data_lease['remaining'] = str(lease['expire_time'] - now).split('.')[0]
# Do not add old leases
if (