diff options
author | Christian Poessinger <christian@poessinger.com> | 2021-03-13 21:08:38 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2021-03-14 14:46:01 +0100 |
commit | 548d9057e3ed66852bb2be62fe770c265712b4f3 (patch) | |
tree | d973e03f769b151f0a8b75fd4ceadbb76afa7a41 /src/conf_mode/protocols_bgp.py | |
parent | 1d43c2ce2a677454713e9aa93fbb71f3516aa992 (diff) | |
download | vyos-1x-548d9057e3ed66852bb2be62fe770c265712b4f3.tar.gz vyos-1x-548d9057e3ed66852bb2be62fe770c265712b4f3.zip |
vrf: T3344: move dynamic routing protocols under "vrf name <name> protocols"
Instead of having the dynamic routing protocols OSPF and BGP residing under
the "protocols vrf <name> [ospf|bgp]" nodes, rather move them directly under
the "vrf name <name> protocols [ospf|bgp]" node. Now all VRF related parts
are placed under the same root node.
This eases the verify steps tremendously, as we do not need to check wheter a
VRF eists or not, it will always exist as we operate under a child node.
Diffstat (limited to 'src/conf_mode/protocols_bgp.py')
-rwxr-xr-x | src/conf_mode/protocols_bgp.py | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/conf_mode/protocols_bgp.py b/src/conf_mode/protocols_bgp.py index 34b829f08..43ca37f9d 100755 --- a/src/conf_mode/protocols_bgp.py +++ b/src/conf_mode/protocols_bgp.py @@ -21,7 +21,6 @@ from sys import argv from vyos.config import Config from vyos.configdict import dict_merge -from vyos.configverify import verify_vrf from vyos.template import is_ip from vyos.template import render_to_string from vyos.util import call @@ -47,15 +46,14 @@ def get_config(config=None): base_path = ['protocols', 'bgp'] # eqivalent of the C foo ? 'a' : 'b' statement - base = vrf and ['protocols', 'vrf', vrf, 'bgp'] or base_path + base = vrf and ['vrf', 'name', vrf, 'protocols', 'bgp'] or base_path bgp = conf.get_config_dict(base, key_mangling=('-', '_'), get_first_key=True) # Assign the name of our VRF context. This MUST be done before the return # statement below, else on deletion we will delete the default instance # instead of the VRF instance. - if vrf: bgp[asn]['vrf'] = vrf + if vrf: bgp.update({'vrf' : vrf}) - # Bail out early if configuration tree does not exist if not conf.exists(base): bgp.update({'deleted' : ''}) return bgp @@ -96,13 +94,19 @@ def verify(bgp): if not bgp: return None - # Check if declared more than one ASN - if len(bgp) > 1: - raise ConfigError('Only one BGP AS number can be defined!') + # FRR bgpd only supports one Autonomous System Number, verify this! + asn = 0 + for key in bgp: + if key.isnumeric(): + asn +=1 + if asn > 1: + raise ConfigError('Only one BGP AS number can be defined!') for asn, asn_config in bgp.items(): - - verify_vrf(asn_config) + # Workaround for https://phabricator.vyos.net/T1711 + # We also have a vrf, and deleted key now - so we can only veriy "numbers" + if not asn.isnumeric(): + continue # Common verification for both peer-group and neighbor statements for neighbor in ['neighbor', 'peer_group']: @@ -202,6 +206,8 @@ def generate(bgp): # of the config dict asn = list(bgp.keys())[0] bgp[asn]['asn'] = asn + if 'vrf' in bgp: + bgp[asn]['vrf'] = bgp['vrf'] bgp['new_frr_config'] = render_to_string('frr/bgp.frr.tmpl', bgp[asn]) return None |