summaryrefslogtreecommitdiff
path: root/src/op_mode/dhcp.py
diff options
context:
space:
mode:
authorIndrajit Raychaudhuri <irc@indrajit.com>2023-12-27 01:51:35 -0600
committerIndrajit Raychaudhuri <irc@indrajit.com>2023-12-29 00:37:56 -0600
commit745b9ea8f0df58ccd68215360b0375e89c0632a8 (patch)
tree3c0411338c62518e6fb3fe1be89b1c4bbd39822a /src/op_mode/dhcp.py
parent6cf6121b1bf0c3495cb2abc37c34330b422d4d16 (diff)
downloadvyos-1x-745b9ea8f0df58ccd68215360b0375e89c0632a8.tar.gz
vyos-1x-745b9ea8f0df58ccd68215360b0375e89c0632a8.zip
dhcp: T3316: Adjust kea lease files' location and permissions
Move the kea lease file to a separate directory `/config/dhcp` that `kea` process can write to so that subprocesses spawned by `kea` process can operate on the lease files. To allow `kea` process to write to `/config/dhcp`, add `_kea` user to `vyattacfg` group. And the lease files are owned completely by `_kea` user to play well with `kea-lfc` process. Specifically, this is necessary for `kea-lfc` which is spawned by `kea` process to clean up expired leases. Since `kea-lfc` creates additional backup lease files, it needs write access to the lease file directory. Additionally, change the extension of the lease file from `.leases` to `.csv` to reflect the actual file format.
Diffstat (limited to 'src/op_mode/dhcp.py')
-rwxr-xr-xsrc/op_mode/dhcp.py9
1 files changed, 3 insertions, 6 deletions
diff --git a/src/op_mode/dhcp.py b/src/op_mode/dhcp.py
index a9271ea79..02f4d5bbb 100755
--- a/src/op_mode/dhcp.py
+++ b/src/op_mode/dhcp.py
@@ -31,9 +31,6 @@ from vyos.configquery import ConfigTreeQuery
from vyos.kea import kea_get_active_config
from vyos.kea import kea_get_pool_from_subnet_id
from vyos.kea import kea_parse_leases
-from vyos.utils.dict import dict_search
-from vyos.utils.file import read_file
-from vyos.utils.process import cmd
from vyos.utils.process import is_systemd_service_running
time_string = "%a %b %d %H:%M:%S %Z %Y"
@@ -79,8 +76,8 @@ def _get_raw_server_leases(family='inet', pool=None, sorted=None, state=[], orig
Get DHCP server leases
:return list
"""
- lease_file = '/config/dhcp6.leases' if family == 'inet6' else '/config/dhcp4.leases'
- data = []
+ inet_suffix = '6' if family == 'inet6' else '4'
+ lease_file = f'/config/dhcp/dhcp{inet_suffix}-leases.csv'
leases = kea_parse_leases(lease_file)
if pool is None:
@@ -88,9 +85,9 @@ def _get_raw_server_leases(family='inet', pool=None, sorted=None, state=[], orig
else:
pool = [pool]
- inet_suffix = '6' if family == 'inet6' else '4'
active_config = kea_get_active_config(inet_suffix)
+ data = []
for lease in leases:
data_lease = {}
data_lease['ip'] = lease['address']