summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2026-06-18 16:32:27 +0200
committerGitHub <noreply@github.com>2026-06-18 16:32:27 +0200
commit177c5e837073789431e945620dca6a2ee0b1927f (patch)
treef1f2946178c08e4cf322fdb0ce52b847e1adf77a /src
parentd3986571522e36f0fcf233e30e9589d4f239cf51 (diff)
parent87ce309c85d8b20ea8383d00595bca27aad1f824 (diff)
downloadvyos-1x-177c5e837073789431e945620dca6a2ee0b1927f.tar.gz
vyos-1x-177c5e837073789431e945620dca6a2ee0b1927f.zip
Merge pull request #5237 from indrajitr/dhcp-leases-extended-options
dhcp: T8941: Support filter and sorting combination on DHCPv4/v6 server lease entries in op mode
Diffstat (limited to 'src')
-rwxr-xr-xsrc/op_mode/dhcp.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/op_mode/dhcp.py b/src/op_mode/dhcp.py
index 1f8d85823..7a4c61fee 100755
--- a/src/op_mode/dhcp.py
+++ b/src/op_mode/dhcp.py
@@ -63,6 +63,7 @@ sort_valid_inet = [
sort_valid_inet6 = [
'end',
'duid',
+ 'hostname',
'ip',
'last_communication',
'pool',
@@ -70,7 +71,7 @@ sort_valid_inet6 = [
'state',
'type',
]
-mapping_sort_valid = ['mac', 'ip', 'pool', 'duid']
+mapping_sort_valid = ['mac', 'hostname', 'ip', 'pool', 'duid']
stale_warn_msg = 'DHCP server is configured but not started. Data may be stale.'
@@ -91,9 +92,9 @@ def _get_raw_server_leases(
if sorted:
if sorted == 'ip':
- mappings.sort(key=lambda x: ip_address(x['ip']))
+ mappings.sort(key=lambda x: ip_address(val) if (val := x.get('ip')) else '')
else:
- mappings.sort(key=lambda x: x[sorted])
+ mappings.sort(key=lambda x: x.get(sorted) or '')
return mappings
@@ -226,9 +227,9 @@ def _get_raw_server_static_mappings(config, family='inet', pool=None, sorted=Non
if sorted:
if sorted == 'ip':
- mappings.sort(key=lambda x: ip_address(x['ip']))
+ mappings.sort(key=lambda x: ip_address(val) if (val := x.get('ip')) else '')
else:
- mappings.sort(key=lambda x: x[sorted])
+ mappings.sort(key=lambda x: x.get(sorted) or '')
return mappings
@@ -239,10 +240,11 @@ def _get_formatted_server_static_mappings(raw_data):
pool = entry.get('pool')
subnet = entry.get('subnet')
hostname = entry.get('hostname')
- ip_addr = entry.get('ip', 'N/A')
- mac_addr = entry.get('mac', 'N/A')
- duid = entry.get('duid', 'N/A')
- desc = entry.get('description', 'N/A')
+ # These fields may be either None or '', display 'N/A' in both cases
+ ip_addr = entry.get('ip') or 'N/A'
+ mac_addr = entry.get('mac') or 'N/A'
+ duid = entry.get('duid') or 'N/A'
+ desc = entry.get('description') or 'N/A'
data_entries.append([pool, subnet, hostname, ip_addr, mac_addr, duid, desc])
headers = [