summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/vyos/defaults.py2
-rw-r--r--python/vyos/frrender.py15
-rw-r--r--python/vyos/kea.py11
-rwxr-xr-xpython/vyos/template.py16
4 files changed, 36 insertions, 8 deletions
diff --git a/python/vyos/defaults.py b/python/vyos/defaults.py
index 43cde38e9..25d7fd50c 100644
--- a/python/vyos/defaults.py
+++ b/python/vyos/defaults.py
@@ -61,6 +61,8 @@ config_files = {
config_status = '/tmp/vyos-config-status'
api_config_state = '/run/http-api-state'
frr_debug_enable = '/tmp/vyos.frr.debug'
+static_route_dhcp_interfaces_path = '/tmp/static_dhcp_interfaces'
+vyos_configd_socket_path = 'ipc:///run/vyos-configd.sock'
cfg_group = 'vyattacfg'
diff --git a/python/vyos/frrender.py b/python/vyos/frrender.py
index decec8aa2..91fd3667d 100644
--- a/python/vyos/frrender.py
+++ b/python/vyos/frrender.py
@@ -31,11 +31,14 @@ from vyos.config import config_dict_merge
from vyos.configdict import get_dhcp_interfaces
from vyos.configdict import get_pppoe_interfaces
from vyos.defaults import frr_debug_enable
+from vyos.defaults import static_route_dhcp_interfaces_path
from vyos.utils.dict import dict_search
from vyos.utils.dict import dict_set_nested
+from vyos.utils.file import read_file
from vyos.utils.file import write_file
from vyos.utils.process import cmd
from vyos.utils.process import rc_cmd
+from vyos.template import get_dhcp_router
from vyos.template import render_to_string
from vyos import ConfigError
@@ -634,6 +637,7 @@ def get_frrender_dict(conf: Config, argv=None) -> dict:
class FRRender:
cached_config_dict = {}
+ cached_dhcp_gateways = {}
def __init__(self):
self._frr_conf = '/run/frr/config/vyos.frr.conf'
@@ -646,11 +650,20 @@ class FRRender:
tmp = type(config_dict)
raise ValueError(f'Config must be of type "dict" and not "{tmp}"!')
+ dhcp_gateways = {
+ interface: get_dhcp_router(interface)
+ for interface in read_file(static_route_dhcp_interfaces_path, '').split()
+ }
- if self.cached_config_dict == config_dict:
+ if (
+ self.cached_config_dict == config_dict
+ and self.cached_dhcp_gateways == dhcp_gateways
+ ):
debug('FRR: NO CHANGES DETECTED')
return False
+
self.cached_config_dict = config_dict
+ self.cached_dhcp_gateways = dhcp_gateways
def inline_helper(config_dict) -> str:
output = '!\n'
diff --git a/python/vyos/kea.py b/python/vyos/kea.py
index 5ce6f47f1..f48cf293d 100644
--- a/python/vyos/kea.py
+++ b/python/vyos/kea.py
@@ -15,6 +15,7 @@
import json
import os
+import re
import socket
from datetime import datetime
@@ -25,7 +26,7 @@ from vyos.template import is_ipv6
from vyos.template import netmask_from_cidr
from vyos.utils.dict import dict_search_args
from vyos.utils.file import file_permissions
-from vyos.utils.process import run
+from vyos.utils.process import run, rc_cmd
kea4_options = {
'name_server': 'domain-name-servers',
@@ -86,6 +87,14 @@ def _find_list_of_dict_index(lst, key='ip', value=''):
idx = next((index for (index, d) in enumerate(lst) if d[key] == value), None)
return idx
+def kea_test_config(process: str, config_path: str) -> tuple[bool, str]:
+ result, output = rc_cmd(f'{process} -t {config_path}')
+
+ if result == 0:
+ return (True, None)
+
+ find = re.search(r'Error encountered:\s([^\n$]+)', output)
+ return (False, find[1] if find else None)
def kea_parse_options(config):
options = []
diff --git a/python/vyos/template.py b/python/vyos/template.py
index 824d42136..f384f752d 100755
--- a/python/vyos/template.py
+++ b/python/vyos/template.py
@@ -422,21 +422,25 @@ def is_file(filename):
@register_filter('get_dhcp_router')
def get_dhcp_router(interface):
- """ Static routes can point to a router received by a DHCP reply. This
+ """Static routes can point to a router received by a DHCP reply. This
helper is used to get the current default router from the DHCP reply.
- Returns False of no router is found, returns the IP address as string if
+ Returns None if no router is found, returns the IP address as string if
a router is found.
"""
- lease_file = directories['isc_dhclient_dir'] + f'/dhclient_{interface}.leases'
+ lease_file = directories['isc_dhclient_dir'] + f'/dhclient_{interface}.lease'
if not os.path.exists(lease_file):
return None
from vyos.utils.file import read_file
for line in read_file(lease_file).splitlines():
- if 'option routers' in line:
- (_, _, address) = line.split()
- return address.rstrip(';')
+ if 'new_routers' in line:
+ (_, address, _) = line.split("'")
+ if not address:
+ return None
+ # Take first one if there are several
+ address = address.split()[0]
+ return address
@register_filter('natural_sort')
def natural_sort(iterable):