Skip to content

Commit

Permalink
dhcp: T7052: Fix remaining time evaluation and formatting errors
Browse files Browse the repository at this point in the history
The remaining time for a lease was not being correctly
evaluated and formatted. As a result, expired leases
show up with `show dhcp server leases`.

Also, the empty hostname should be replaced by '-'.
  • Loading branch information
indrajitr committed Jan 26, 2025
1 parent 10ee7ac commit 9723f10
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions python/vyos/kea.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def kea_get_server_leases(config, inet, pools=[], state=[], origin=None) -> list
)
data_lease['origin'] = 'local' # TODO: Determine remote in HA
# remove trailing dot in 'hostname' to ensure consistency for `vyos-hostsd-client`
data_lease['hostname'] = lease.get('hostname', '-').rstrip('.')
data_lease['hostname'] = lease.get('hostname', '').rstrip('.') or '-'

if inet == '4':
data_lease['mac'] = lease['hw-address']
Expand All @@ -512,7 +512,7 @@ def kea_get_server_leases(config, inet, pools=[], state=[], origin=None) -> list
prefix_len = lease['prefix-len']
data_lease['ip'] += f'/{prefix_len}'

data_lease['remaining'] = '-'
data_lease['remaining'] = ''

if lease['valid-lft'] > 0:
data_lease['remaining'] = lease['expire_timestamp'] - datetime.now(
Expand All @@ -526,7 +526,7 @@ def kea_get_server_leases(config, inet, pools=[], state=[], origin=None) -> list

# Do not add old leases
if (
data_lease['remaining']
data_lease['remaining'] != ''
and data_lease['pool'] in pools
and data_lease['state'] != 'free'
and (not state or state == 'all' or data_lease['state'] in state)
Expand Down

0 comments on commit 9723f10

Please sign in to comment.