diff options
author | Christian Poessinger <christian@poessinger.com> | 2021-04-07 14:53:49 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2021-04-07 14:56:32 +0200 |
commit | ce361fe12c430c792361479e5b5b3228141fd36f (patch) | |
tree | f8454e9d6c67db533a9f9cc2233b293f9384b7ec | |
parent | 44f766a7880e9264487e62f4aacc9f4f635219ed (diff) | |
download | vyos-1x-ce361fe12c430c792361479e5b5b3228141fd36f.tar.gz vyos-1x-ce361fe12c430c792361479e5b5b3228141fd36f.zip |
vrf: T3344: re-add virtual network identifier
Commit 548d9057e3e (vrf: T3344: move dynamic routing protocols under "vrf name
<name> protocols") temporary removed the possibility to specify the VNI for a
given VRF to to changing of the CLI configuration nodes.
As VNI is set inside zebra, we can re-use the now widely deployed frr python
library to configure and change the configuration without any interference to
other FRR daemons.
-rw-r--r-- | data/templates/frr/vrf.frr.tmpl | 9 | ||||
-rw-r--r-- | interface-definitions/include/vni.xml.i | 26 | ||||
-rw-r--r-- | interface-definitions/vrf.xml.in | 1 | ||||
-rwxr-xr-x | src/conf_mode/vrf.py | 21 |
4 files changed, 45 insertions, 12 deletions
diff --git a/data/templates/frr/vrf.frr.tmpl b/data/templates/frr/vrf.frr.tmpl new file mode 100644 index 000000000..299c9719e --- /dev/null +++ b/data/templates/frr/vrf.frr.tmpl @@ -0,0 +1,9 @@ +{% if name is defined and name is not none %} +{% for vrf, vrf_config in name.items() %} +vrf {{ vrf }} +{% if vrf_config.vni is defined and vrf_config.vni is not none %} + vni {{ vrf_config.vni }} +{% endif %} + exit-vrf +{% endfor %} +{% endif %} diff --git a/interface-definitions/include/vni.xml.i b/interface-definitions/include/vni.xml.i index faff4c3c3..be45c0c97 100644 --- a/interface-definitions/include/vni.xml.i +++ b/interface-definitions/include/vni.xml.i @@ -1,12 +1,14 @@ - <leafNode name="vni"> - <properties> - <help>Virtual Network Identifier</help> - <valueHelp> - <format>0-16777214</format> - <description>VXLAN virtual network identifier</description> - </valueHelp> - <constraint> - <validator name="numeric" argument="--range 0-16777214"/> - </constraint> - </properties> - </leafNode> +<!-- include start from vni.xml.i --> +<leafNode name="vni"> + <properties> + <help>Virtual Network Identifier</help> + <valueHelp> + <format>0-16777214</format> + <description>VXLAN virtual network identifier</description> + </valueHelp> + <constraint> + <validator name="numeric" argument="--range 0-16777214"/> + </constraint> + </properties> +</leafNode> +<!-- include end --> diff --git a/interface-definitions/vrf.xml.in b/interface-definitions/vrf.xml.in index 8a56b1bc0..a1ef45868 100644 --- a/interface-definitions/vrf.xml.in +++ b/interface-definitions/vrf.xml.in @@ -85,6 +85,7 @@ <constraintErrorMessage>VRF routing table must be in range from 100 to 2147483647</constraintErrorMessage> </properties> </leafNode> + #include <include/vni.xml.i> </children> </tagNode> </children> diff --git a/src/conf_mode/vrf.py b/src/conf_mode/vrf.py index 414e514c5..a39da8991 100755 --- a/src/conf_mode/vrf.py +++ b/src/conf_mode/vrf.py @@ -23,14 +23,18 @@ from vyos.config import Config from vyos.configdict import node_changed from vyos.ifconfig import Interface from vyos.template import render +from vyos.template import render_to_string from vyos.util import call from vyos.util import cmd from vyos.util import dict_search from vyos.util import get_interface_config from vyos import ConfigError +from vyos import frr from vyos import airbag airbag.enable() +frr_daemon = 'zebra' + config_file = r'/etc/iproute2/rt_tables.d/vyos-vrf.conf' def list_rules(): @@ -123,6 +127,7 @@ def verify(vrf): def generate(vrf): render(config_file, 'vrf/vrf.conf.tmpl', vrf) + vrf['new_frr_config'] = render_to_string('frr/vrf.frr.tmpl', vrf) return None def apply(vrf): @@ -210,6 +215,22 @@ def apply(vrf): if 1000 in [r.get('priority') for r in list_rules() if r.get('priority') == 1000]: call(f'ip {af} rule del pref 1000') + # add configuration to FRR + frr_cfg = frr.FRRConfig() + frr_cfg.load_configuration(frr_daemon) + frr_cfg.modify_section(f'^vrf [a-zA-Z-]*$', '') + frr_cfg.add_before(r'(interface .*|line vty)', vrf['new_frr_config']) + frr_cfg.commit_configuration(frr_daemon) + + # If FRR config is blank, rerun the blank commit x times due to frr-reload + # behavior/bug not properly clearing out on one commit. + if vrf['new_frr_config'] == '': + for a in range(5): + frr_cfg.commit_configuration(frr_daemon) + + # Save configuration to /run/frr/config/frr.conf + frr.save_configuration() + return None if __name__ == '__main__': |