diff options
author | Daniil Baturin <daniil@vyos.io> | 2024-03-09 20:06:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-09 20:06:40 +0100 |
commit | e8a6d3ddb6eb36299dbced2e119ba0699e062350 (patch) | |
tree | aed5859834208a758f251bb729d20ae3caf9eb80 /python/vyos/kea.py | |
parent | da759a46efaaa937edae2440a7743d325ebf99b1 (diff) | |
parent | 0920121eed97889ff33ef84f04a3730242ccb04b (diff) | |
download | vyos-1x-e8a6d3ddb6eb36299dbced2e119ba0699e062350.tar.gz vyos-1x-e8a6d3ddb6eb36299dbced2e119ba0699e062350.zip |
Merge pull request #3106 from sarthurdev/T6102
dhcp: T6102: Fix clear DHCP lease op-mode
Diffstat (limited to 'python/vyos/kea.py')
-rw-r--r-- | python/vyos/kea.py | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/python/vyos/kea.py b/python/vyos/kea.py index 2328d0b00..89ae7ca81 100644 --- a/python/vyos/kea.py +++ b/python/vyos/kea.py @@ -56,6 +56,8 @@ kea6_options = { 'captive_portal': 'v6-captive-portal' } +kea_ctrl_socket = '/run/kea/dhcp{inet}-ctrl-socket' + def kea_parse_options(config): options = [] @@ -294,7 +296,9 @@ def kea6_parse_subnet(subnet, config): return out -def _ctrl_socket_command(path, command, args=None): +def _ctrl_socket_command(inet, command, args=None): + path = kea_ctrl_socket.format(inet=inet) + if not os.path.exists(path): return None @@ -319,19 +323,25 @@ def _ctrl_socket_command(path, command, args=None): return json.loads(result.decode('utf-8')) def kea_get_leases(inet): - ctrl_socket = f'/run/kea/dhcp{inet}-ctrl-socket' - - leases = _ctrl_socket_command(ctrl_socket, f'lease{inet}-get-all') + leases = _ctrl_socket_command(inet, f'lease{inet}-get-all') if not leases or 'result' not in leases or leases['result'] != 0: return [] return leases['arguments']['leases'] -def kea_get_active_config(inet): - ctrl_socket = f'/run/kea/dhcp{inet}-ctrl-socket' +def kea_delete_lease(inet, ip_address): + args = {'ip-address': ip_address} - config = _ctrl_socket_command(ctrl_socket, 'config-get') + result = _ctrl_socket_command(inet, f'lease{inet}-del', args) + + if result and 'result' in result: + return result['result'] == 0 + + return False + +def kea_get_active_config(inet): + config = _ctrl_socket_command(inet, 'config-get') if not config or 'result' not in config or config['result'] != 0: return None |