summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/vyos/kea.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/python/vyos/kea.py b/python/vyos/kea.py
index 74ffa3fb1..068e2cf7a 100644
--- a/python/vyos/kea.py
+++ b/python/vyos/kea.py
@@ -89,6 +89,14 @@ def _find_list_of_dict_index(lst, key='ip', value=''):
return idx
+def _read_posix_timezone(tz_name):
+ try:
+ with open(f'/usr/share/zoneinfo/{tz_name}', 'rb') as f:
+ return f.read().split(b'\n')[-2].decode('utf-8').replace(',', '\\,')
+ except (FileNotFoundError, IOError, IndexError) as e:
+ raise ConfigError(f'Failed to read timezone data for: {tz_name}') from e
+
+
def kea_test_config(process: str, config_path: str) -> tuple[bool, str]:
result, output = rc_cmd(f'{process} -t {config_path}')
@@ -143,9 +151,7 @@ def kea_parse_options(config):
)
if 'time_zone' in config:
- with open('/usr/share/zoneinfo/' + config['time_zone'], 'rb') as f:
- tz_string = f.read().split(b'\n')[-2].decode('utf-8').replace(',', '\\,')
-
+ tz_string = _read_posix_timezone(config['time_zone'])
options.append({'name': 'pcode', 'data': tz_string})
options.append({'name': 'tcode', 'data': config['time_zone']})
@@ -289,6 +295,11 @@ def kea6_parse_options(config):
if hosts:
options.append({'name': 'sip-server-dns', 'data': ', '.join(hosts)})
+ if 'time_zone' in config:
+ tz_string = _read_posix_timezone(config['time_zone'])
+ options.append({'name': 'new-posix-timezone', 'data': tz_string})
+ options.append({'name': 'new-tzdb-timezone', 'data': config['time_zone']})
+
cisco_tftp = dict_search_args(config, 'vendor_option', 'cisco', 'tftp-server')
if cisco_tftp:
options.append(