summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/templates/high-availability/keepalived.conf.j24
-rw-r--r--interface-definitions/high-availability.xml.in23
-rw-r--r--python/vyos/template.py17
3 files changed, 33 insertions, 11 deletions
diff --git a/data/templates/high-availability/keepalived.conf.j2 b/data/templates/high-availability/keepalived.conf.j2
index 240161748..c0d66ae54 100644
--- a/data/templates/high-availability/keepalived.conf.j2
+++ b/data/templates/high-availability/keepalived.conf.j2
@@ -138,8 +138,8 @@ vrrp_instance {{ name }} {
{% endif %}
{% if group_config.excluded_address is vyos_defined %}
virtual_ipaddress_excluded {
-{% for addr in group_config.excluded_address %}
- {{ addr }}
+{% for addr, addr_config in group_config.excluded_address.items() %}
+ {{ addr }}{{ ' dev ' + addr_config.interface if addr_config.interface is vyos_defined }}
{% endfor %}
}
{% endif %}
diff --git a/interface-definitions/high-availability.xml.in b/interface-definitions/high-availability.xml.in
index 558404882..7108aa06c 100644
--- a/interface-definitions/high-availability.xml.in
+++ b/interface-definitions/high-availability.xml.in
@@ -294,25 +294,34 @@
#include <include/generic-interface-broadcast.xml.i>
</children>
</tagNode>
- <leafNode name="excluded-address">
+ <tagNode name="excluded-address">
<properties>
<help>Virtual address (If you need additional IPv4 and IPv6 in same group)</help>
<valueHelp>
+ <format>ipv4net</format>
+ <description>IPv4 address and prefix length</description>
+ </valueHelp>
+ <valueHelp>
+ <format>ipv6net</format>
+ <description>IPv6 address and prefix length</description>
+ </valueHelp>
+ <valueHelp>
<format>ipv4</format>
- <description>IP address</description>
+ <description>IPv4 address</description>
</valueHelp>
<valueHelp>
<format>ipv6</format>
<description>IPv6 address</description>
</valueHelp>
- <multi/>
<constraint>
- <validator name="ipv4-host"/>
- <validator name="ipv6-host"/>
+ <validator name="ip-host"/>
+ <validator name="ip-address"/>
</constraint>
- <constraintErrorMessage>Virtual address must be a valid IPv4 or IPv6 address with prefix length (e.g. 192.0.2.3/24 or 2001:db8:ff::10/64)</constraintErrorMessage>
</properties>
- </leafNode>
+ <children>
+ #include <include/generic-interface-broadcast.xml.i>
+ </children>
+ </tagNode>
<leafNode name="vrid">
<properties>
<help>Virtual router identifier</help>
diff --git a/python/vyos/template.py b/python/vyos/template.py
index bde8e3554..392322d46 100644
--- a/python/vyos/template.py
+++ b/python/vyos/template.py
@@ -1,4 +1,4 @@
-# Copyright 2019-2023 VyOS maintainers and contributors <maintainers@vyos.io>
+# Copyright 2019-2024 VyOS maintainers and contributors <maintainers@vyos.io>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -32,8 +32,21 @@ _TESTS = {}
# reuse Environments with identical settings to improve performance
@functools.lru_cache(maxsize=2)
def _get_environment(location=None):
+ from os import getenv
+
if location is None:
- loc_loader=FileSystemLoader(directories["templates"])
+ # Sometimes functions that rely on templates need to be executed outside of VyOS installations:
+ # for example, installer functions are executed for image builds,
+ # and anything may be invoked for testing from a developer's machine.
+ # This environment variable allows running any unmodified code
+ # with a custom template location.
+ location_env_var = getenv("VYOS_TEMPLATE_DIR")
+ if location_env_var:
+ print(f"Using environment variable {location_env_var}")
+ template_dir = location_env_var
+ else:
+ template_dir = directories["templates"]
+ loc_loader=FileSystemLoader(template_dir)
else:
loc_loader=FileSystemLoader(location)
env = Environment(