Skip to content

Commit 3d466a4

Browse files
David VølkerDavid Vølker
David Vølker
authored and
David Vølker
committed
kea: T6211: update dhcp to get pool size for vrf aswell
1 parent 6a9a132 commit 3d466a4

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/op_mode/dhcp.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,13 @@ def _get_formatted_server_leases(raw_data, family='inet'):
166166
return output
167167

168168

169-
def _get_pool_size(pool, family='inet'):
169+
def _get_pool_size(pool, family='inet', vrf=''):
170170
v = 'v6' if family == 'inet6' else ''
171-
base = f'service dhcp{v}-server shared-network-name {pool}'
171+
# if vrf is set get the correct base for config
172+
if vrf:
173+
base = f'vrf name {vrf} service dhcp{v}-server shared-network-name {pool}'
174+
else:
175+
base = f'service dhcp{v}-server shared-network-name {pool}'
172176
size = 0
173177
subnets = config.list_nodes(f'{base} subnet')
174178
for subnet in subnets:
@@ -185,7 +189,7 @@ def _get_pool_size(pool, family='inet'):
185189
return size
186190

187191

188-
def _get_raw_server_pool_statistics(config, family='inet', pool=None):
192+
def _get_raw_server_pool_statistics(config, family='inet', vrf='', pool=None):
189193
inet_suffix = '6' if family == 'inet6' else '4'
190194
pools = [pool] if pool else kea_get_dhcp_pools(config, inet_suffix)
191195

@@ -269,11 +273,20 @@ def _verify_server(func):
269273
def _wrapper(*args, **kwargs):
270274
config = ConfigTreeQuery()
271275
family = kwargs.get('family')
276+
vrf = kwargs.get('vrf')
272277
v = 'v6' if family == 'inet6' else ''
273-
unconf_message = f'DHCP{v} server is not configured'
278+
274279
# Check if config does not exist
275-
if not config.exists(f'service dhcp{v}-server'):
276-
raise vyos.opmode.UnconfiguredSubsystem(unconf_message)
280+
if vrf:
281+
unconf_message = f'DHCP{v} server is not configured for VRF {vrf}'
282+
if not config.exists(f'vrf name {vrf} service dhcp{v}-server'):
283+
raise vyos.opmode.UnconfiguredSubsystem(unconf_message)
284+
else:
285+
unconf_message = f'DHCP{v} server is not configured'
286+
if not config.exists(f'service dhcp{v}-server'):
287+
raise vyos.opmode.UnconfiguredSubsystem(unconf_message)
288+
289+
# return
277290
return func(*args, **kwargs)
278291

279292
return _wrapper
@@ -321,7 +334,9 @@ def show_server_pool_statistics(
321334
if pool and active_pools and pool not in active_pools:
322335
raise vyos.opmode.IncorrectValue(f'DHCP{v} pool "{pool}" does not exist!')
323336

324-
pool_data = _get_raw_server_pool_statistics(active_config, family=family, pool=pool)
337+
pool_data = _get_raw_server_pool_statistics(
338+
active_config, family=family, vrf=vrf, pool=pool
339+
)
325340
if raw:
326341
return pool_data
327342
else:

0 commit comments

Comments
 (0)