diff options
author | sarthurdev <965089+sarthurdev@users.noreply.github.com> | 2024-03-08 16:36:25 +0100 |
---|---|---|
committer | sarthurdev <965089+sarthurdev@users.noreply.github.com> | 2024-03-08 16:36:25 +0100 |
commit | 0920121eed97889ff33ef84f04a3730242ccb04b (patch) | |
tree | 6c1253ed15f4dce5110c2946502bab2f8b064e29 | |
parent | c55140f8bbd8e8f0e7c112a419027b65d479add6 (diff) | |
download | vyos-1x-0920121eed97889ff33ef84f04a3730242ccb04b.tar.gz vyos-1x-0920121eed97889ff33ef84f04a3730242ccb04b.zip |
dhcp: T3316: De-duplicate Kea control socket variable
-rw-r--r-- | python/vyos/kea.py | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/python/vyos/kea.py b/python/vyos/kea.py index 5aa91e652..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,9 +323,7 @@ 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 [] @@ -329,11 +331,9 @@ def kea_get_leases(inet): return leases['arguments']['leases'] def kea_delete_lease(inet, ip_address): - ctrl_socket = f'/run/kea/dhcp{inet}-ctrl-socket' - args = {'ip-address': ip_address} - result = _ctrl_socket_command(ctrl_socket, f'lease{inet}-del', args) + result = _ctrl_socket_command(inet, f'lease{inet}-del', args) if result and 'result' in result: return result['result'] == 0 @@ -341,9 +341,7 @@ def kea_delete_lease(inet, ip_address): return False def kea_get_active_config(inet): - ctrl_socket = f'/run/kea/dhcp{inet}-ctrl-socket' - - config = _ctrl_socket_command(ctrl_socket, 'config-get') + config = _ctrl_socket_command(inet, 'config-get') if not config or 'result' not in config or config['result'] != 0: return None |