diff options
| author | Daniil Baturin <daniil@vyos.io> | 2025-10-21 15:15:18 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-21 15:15:18 +0100 |
| commit | 33099a929ad51b980b77d7427bbb89cd71a560b6 (patch) | |
| tree | 12d7a2a95d8e42b7788ed81435d923a870f73577 /python | |
| parent | fd8794f36b487ba2102cc50437056e93eb62f7f3 (diff) | |
| parent | d290b2661f0d71168a4d6b16691f48b7fb741a4c (diff) | |
| download | vyos-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-x | python/vyos/template.py | 16 |
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): |
