summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2025-10-21 15:15:18 +0100
committerGitHub <noreply@github.com>2025-10-21 15:15:18 +0100
commit33099a929ad51b980b77d7427bbb89cd71a560b6 (patch)
tree12d7a2a95d8e42b7788ed81435d923a870f73577 /python
parentfd8794f36b487ba2102cc50437056e93eb62f7f3 (diff)
parentd290b2661f0d71168a4d6b16691f48b7fb741a4c (diff)
downloadvyos-1x-33099a929ad51b980b77d7427bbb89cd71a560b6.tar.gz
vyos-1x-33099a929ad51b980b77d7427bbb89cd71a560b6.zip
Merge pull request #4783 from hedrok/T5942-failover-dhcp-gateway
T5942: Make failover support dhcp-interface
Diffstat (limited to 'python')
-rwxr-xr-xpython/vyos/template.py16
1 files changed, 10 insertions, 6 deletions
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):