diff options
author | metron2 <metron2@users.noreply.github.com> | 2025-01-06 17:55:13 -0500 |
---|---|---|
committer | Indrajit Raychaudhuri <irc@indrajit.com> | 2025-01-26 12:31:31 -0600 |
commit | 529c24a9d550b30ba7fabcbae3a5bc0d5d35c647 (patch) | |
tree | 4cbb42bec5484f4122875aac02a37697f44adad3 /python | |
parent | 10ee7ac1d2bfd20bd11b5ebaa33c2f07dd561d48 (diff) | |
download | vyos-1x-529c24a9d550b30ba7fabcbae3a5bc0d5d35c647.tar.gz vyos-1x-529c24a9d550b30ba7fabcbae3a5bc0d5d35c647.zip |
T6998: dhcpy.py - fix datetime to be timezone aware
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/kea.py | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/python/vyos/kea.py b/python/vyos/kea.py index 951c83693..8b3628db1 100644 --- a/python/vyos/kea.py +++ b/python/vyos/kea.py @@ -476,9 +476,7 @@ def kea_get_server_leases(config, inet, pools=[], state=[], origin=None) -> list lifetime = lease['valid-lft'] expiry = lease['cltt'] + lifetime - lease['start_timestamp'] = datetime.fromtimestamp( - expiry - lifetime, timezone.utc - ) + lease['start_timestamp'] = datetime.fromtimestamp(lease['cltt'], timezone.utc) lease['expire_timestamp'] = ( datetime.fromtimestamp(expiry, timezone.utc) if expiry else None ) @@ -515,14 +513,10 @@ def kea_get_server_leases(config, inet, pools=[], state=[], origin=None) -> list data_lease['remaining'] = '-' if lease['valid-lft'] > 0: - data_lease['remaining'] = lease['expire_timestamp'] - datetime.now( - timezone.utc - ) - - if data_lease['remaining'].days >= 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(data_lease['remaining']).split('.')[0] + data_lease['remaining'] = str(lease['expire_timestamp'] - datetime.now(timezone.utc)).split('.')[0] # Do not add old leases if ( |