diff options
author | Christian Breunig <christian@breunig.cc> | 2024-12-11 20:14:45 +0100 |
---|---|---|
committer | Christian Breunig <christian@breunig.cc> | 2024-12-16 22:24:50 +0100 |
commit | 55683a8406e17408021437cb35b57c48bd8b2ab1 (patch) | |
tree | bc149befb6ceadc94bf57503c65dd9267339edf0 | |
parent | 779f311e7fe81e3c85de28f13e4e12e33b255483 (diff) | |
download | vyos-1x-55683a8406e17408021437cb35b57c48bd8b2ab1.tar.gz vyos-1x-55683a8406e17408021437cb35b57c48bd8b2ab1.zip |
configd: T6746: handle FRR config reload as last step in commit
-rw-r--r-- | python/vyos/configdict.py | 22 | ||||
-rw-r--r-- | python/vyos/configverify.py | 5 | ||||
-rw-r--r-- | python/vyos/frrender.py | 5 | ||||
-rwxr-xr-x | src/conf_mode/policy.py | 4 | ||||
-rwxr-xr-x | src/conf_mode/protocols_babel.py | 4 | ||||
-rwxr-xr-x | src/conf_mode/protocols_bfd.py | 4 | ||||
-rwxr-xr-x | src/conf_mode/protocols_bgp.py | 42 | ||||
-rwxr-xr-x | src/conf_mode/protocols_eigrp.py | 21 | ||||
-rwxr-xr-x | src/conf_mode/protocols_isis.py | 65 | ||||
-rwxr-xr-x | src/conf_mode/protocols_mpls.py | 4 | ||||
-rw-r--r-- | src/conf_mode/protocols_openfabric.py | 4 | ||||
-rwxr-xr-x | src/conf_mode/protocols_ospf.py | 17 | ||||
-rwxr-xr-x | src/conf_mode/protocols_ospfv3.py | 17 | ||||
-rwxr-xr-x | src/conf_mode/protocols_pim.py | 4 | ||||
-rwxr-xr-x | src/conf_mode/protocols_pim6.py | 4 | ||||
-rwxr-xr-x | src/conf_mode/protocols_rip.py | 4 | ||||
-rwxr-xr-x | src/conf_mode/protocols_ripng.py | 4 | ||||
-rwxr-xr-x | src/conf_mode/protocols_rpki.py | 4 | ||||
-rwxr-xr-x | src/conf_mode/protocols_segment-routing.py | 4 | ||||
-rwxr-xr-x | src/conf_mode/protocols_static.py | 26 | ||||
-rwxr-xr-x | src/services/vyos-configd | 2 |
21 files changed, 114 insertions, 152 deletions
diff --git a/python/vyos/configdict.py b/python/vyos/configdict.py index baffd94dd..f5e84267e 100644 --- a/python/vyos/configdict.py +++ b/python/vyos/configdict.py @@ -666,7 +666,7 @@ def get_accel_dict(config, base, chap_secrets, with_pki=False): return dict -def get_frrender_dict(conf) -> dict: +def get_frrender_dict(conf, argv=None) -> dict: from copy import deepcopy from vyos.config import config_dict_merge from vyos.frrender import frr_protocols @@ -675,6 +675,9 @@ def get_frrender_dict(conf) -> dict: # returned to the caller dict = {} + if argv and len(argv) > 1: + dict['vrf_context'] = argv[1] + def dict_helper_ospf_defaults(ospf, path): # We have gathered the dict representation of the CLI, but there are default # options which we need to update into the dictionary retrived. @@ -1024,7 +1027,11 @@ def get_frrender_dict(conf) -> dict: if 'bgp' in dict: dict['bgp']['dependent_vrfs'].update({vrf_name : {'protocols': tmp} }) - vrf['name'][vrf_name]['protocols'].update({'bgp' : tmp}) + + if 'protocols' not in vrf['name'][vrf_name]: + vrf['name'][vrf_name].update({'protocols': {'bgp' : tmp}}) + else: + vrf['name'][vrf_name]['protocols'].update({'bgp' : tmp}) # We need to check the CLI if the EIGRP node is present and thus load in all the default # values present on the CLI - that's why we have if conf.exists() @@ -1125,15 +1132,16 @@ def get_frrender_dict(conf) -> dict: dict.update({'vrf' : vrf}) + if os.path.exists(frr_debug_enable): + print('======== < BEGIN > ==========') + import pprint + pprint.pprint(dict) + print('========= < END > ===========') + # Use singleton instance of the FRR render class if hasattr(conf, 'frrender_cls'): frrender = getattr(conf, 'frrender_cls') dict.update({'frrender_cls' : frrender}) frrender.generate(dict) - if os.path.exists(frr_debug_enable): - print('======== < BEGIN > ==========') - import pprint - pprint.pprint(dict) - print('========= < END > ===========') return dict diff --git a/python/vyos/configverify.py b/python/vyos/configverify.py index 4450dc16b..4084425b1 100644 --- a/python/vyos/configverify.py +++ b/python/vyos/configverify.py @@ -538,7 +538,10 @@ def verify_eapol(config: dict): for ca_cert in config['eapol']['ca_certificate']: verify_pki_ca_certificate(config, ca_cert) -def has_frr_protocol_in_dict(config_dict: dict, protocol: str, vrf: str=None) -> bool: +def has_frr_protocol_in_dict(config_dict: dict, protocol: str) -> bool: + vrf = None + if config_dict and 'vrf_context' in config_dict: + vrf = config_dict['vrf_context'] if vrf and protocol in (dict_search(f'vrf.name.{vrf}.protocols', config_dict) or []): return True if config_dict and protocol in config_dict: diff --git a/python/vyos/frrender.py b/python/vyos/frrender.py index e02094bbb..f1bb39094 100644 --- a/python/vyos/frrender.py +++ b/python/vyos/frrender.py @@ -44,7 +44,8 @@ class FRRender: def generate(self, config): if not isinstance(config, dict): - raise ValueError('config must be of type dict') + tmp = type(config) + raise ValueError(f'Config must be of type "dict" and not "{tmp}"!') def inline_helper(config_dict) -> str: output = '!\n' @@ -136,7 +137,7 @@ class FRRender: emsg = '' while count < count_max: count += 1 - print('FRR: Reloading configuration - tries:', count, 'Python class ID:', id(self)) + debug(f'FRR: Reloading configuration - tries: {count} | Python class ID: {id(self)}') cmdline = '/usr/lib/frr/frr-reload.py --reload' if DEBUG_ON: diff --git a/src/conf_mode/policy.py b/src/conf_mode/policy.py index 2122cb032..4abb150ac 100755 --- a/src/conf_mode/policy.py +++ b/src/conf_mode/policy.py @@ -262,12 +262,12 @@ def verify(config_dict): def generate(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().generate(config_dict) return None def apply(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().apply() return None diff --git a/src/conf_mode/protocols_babel.py b/src/conf_mode/protocols_babel.py index f458493c2..af0751e02 100755 --- a/src/conf_mode/protocols_babel.py +++ b/src/conf_mode/protocols_babel.py @@ -89,12 +89,12 @@ def verify(config_dict): def generate(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().generate(config_dict) return None def apply(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().apply() return None diff --git a/src/conf_mode/protocols_bfd.py b/src/conf_mode/protocols_bfd.py index d8b19fa0e..623801897 100755 --- a/src/conf_mode/protocols_bfd.py +++ b/src/conf_mode/protocols_bfd.py @@ -77,11 +77,11 @@ def verify(config_dict): return None def generate(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().generate(config_dict) def apply(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().apply() return None diff --git a/src/conf_mode/protocols_bgp.py b/src/conf_mode/protocols_bgp.py index 2a4bcbadf..db3123bd3 100755 --- a/src/conf_mode/protocols_bgp.py +++ b/src/conf_mode/protocols_bgp.py @@ -35,17 +35,13 @@ from vyos import ConfigError from vyos import airbag airbag.enable() -vrf = None -if len(argv) > 1: - vrf = argv[1] - def get_config(config=None): if config: conf = config else: conf = Config() - return get_frrender_dict(conf) + return get_frrender_dict(conf, argv) def verify_vrf_as_import(search_vrf_name: str, afi_name: str, vrfs_config: dict) -> bool: """ @@ -179,23 +175,28 @@ def verify_afi(peer_config, bgp_config): return False def verify(config_dict): - global vrf - if not has_frr_protocol_in_dict(config_dict, 'bgp', vrf): + + print('====== verify() ======') + import pprint + pprint.pprint(config_dict) + + if not has_frr_protocol_in_dict(config_dict, 'bgp'): return None + vrf = None + if 'vrf_context' in config_dict: + vrf = config_dict['vrf_context'] + # eqivalent of the C foo ? 'a' : 'b' statement bgp = vrf and config_dict['vrf']['name'][vrf]['protocols']['bgp'] or config_dict['bgp'] bgp['policy'] = config_dict['policy'] - if vrf: - bgp['vrf'] = vrf - if 'deleted' in bgp: - if 'vrf' in bgp: + if vrf: # Cannot delete vrf if it exists in import vrf list in other vrfs for tmp_afi in ['ipv4_unicast', 'ipv6_unicast']: - if verify_vrf_as_import(bgp['vrf'], tmp_afi, bgp['dependent_vrfs']): - raise ConfigError(f'Cannot delete VRF instance "{bgp["vrf"]}", ' \ + if verify_vrf_as_import(vrf, tmp_afi, bgp['dependent_vrfs']): + raise ConfigError(f'Cannot delete VRF instance "{vrf}", ' \ 'unconfigure "import vrf" commands!') else: # We are running in the default VRF context, thus we can not delete @@ -234,9 +235,8 @@ def verify(config_dict): for interface in bgp['interface']: error_msg = f'Interface "{interface}" belongs to different VRF instance' tmp = get_interface_vrf(interface) - if 'vrf' in bgp: - if bgp['vrf'] != tmp: - vrf = bgp['vrf'] + if vrf: + if vrf != tmp: raise ConfigError(f'{error_msg} "{vrf}"!') elif tmp != 'default': raise ConfigError(f'{error_msg} "{tmp}"!') @@ -337,10 +337,8 @@ def verify(config_dict): # Only checks for ipv4 and ipv6 neighbors # Check if neighbor address is assigned as system interface address - vrf = None vrf_error_msg = f' in default VRF!' - if 'vrf' in bgp: - vrf = bgp['vrf'] + if vrf: vrf_error_msg = f' in VRF "{vrf}"!' if is_ip(peer) and is_addr_assigned(peer, vrf): @@ -482,7 +480,7 @@ def verify(config_dict): f'{afi} administrative distance {key}!') if afi in ['ipv4_unicast', 'ipv6_unicast']: - vrf_name = bgp['vrf'] if dict_search('vrf', bgp) else 'default' + vrf_name = vrf if vrf else 'default' # Verify if currant VRF contains rd and route-target options # and does not exist in import list in other VRFs if dict_search(f'rd.vpn.export', afi_config): @@ -556,12 +554,12 @@ def verify(config_dict): return None def generate(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().generate(config_dict) return None def apply(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().apply() return None diff --git a/src/conf_mode/protocols_eigrp.py b/src/conf_mode/protocols_eigrp.py index 4f56d2b94..33812d350 100755 --- a/src/conf_mode/protocols_eigrp.py +++ b/src/conf_mode/protocols_eigrp.py @@ -26,23 +26,22 @@ from vyos import ConfigError from vyos import airbag airbag.enable() -vrf = None -if len(argv) > 1: - vrf = argv[1] - def get_config(config=None): if config: conf = config else: conf = Config() - return get_frrender_dict(conf) + return get_frrender_dict(conf, argv) def verify(config_dict): - global vrf - if not has_frr_protocol_in_dict(config_dict, 'eigrp', vrf): + if not has_frr_protocol_in_dict(config_dict, 'eigrp'): return None + vrf = None + if 'vrf_context' in config_dict: + vrf = config_dict['vrf_context'] + # eqivalent of the C foo ? 'a' : 'b' statement eigrp = vrf and config_dict['vrf']['name'][vrf]['protocols']['eigrp'] or config_dict['eigrp'] eigrp['policy'] = config_dict['policy'] @@ -50,16 +49,16 @@ def verify(config_dict): if 'system_as' not in eigrp: raise ConfigError('EIGRP system-as must be defined!') - if 'vrf' in eigrp: - verify_vrf(eigrp) + if vrf: + verify_vrf({'vrf': vrf}) def generate(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().generate(config_dict) return None def apply(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().apply() return None diff --git a/src/conf_mode/protocols_isis.py b/src/conf_mode/protocols_isis.py index 9e494ecc8..7a54685bb 100755 --- a/src/conf_mode/protocols_isis.py +++ b/src/conf_mode/protocols_isis.py @@ -30,65 +30,22 @@ from vyos import ConfigError from vyos import airbag airbag.enable() -vrf = None -if len(argv) > 1: - vrf = argv[1] - def get_config(config=None): if config: conf = config else: conf = Config() - return get_frrender_dict(conf) - - - # base_path = ['protocols', 'isis'] - - # # eqivalent of the C foo ? 'a' : 'b' statement - # base = vrf and ['vrf', 'name', vrf, 'protocols', 'isis'] or base_path - # isis = conf.get_config_dict(base, key_mangling=('-', '_'), - # get_first_key=True, - # no_tag_node_value_mangle=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: isis['vrf'] = vrf - - # # FRR has VRF support for different routing daemons. As interfaces belong - # # to VRFs - or the global VRF, we need to check for changed interfaces so - # # that they will be properly rendered for the FRR config. Also this eases - # # removal of interfaces from the running configuration. - # interfaces_removed = node_changed(conf, base + ['interface']) - # if interfaces_removed: - # isis['interface_removed'] = list(interfaces_removed) - - # # Bail out early if configuration tree does no longer exist. this must - # # be done after retrieving the list of interfaces to be removed. - # if not conf.exists(base): - # isis.update({'deleted' : ''}) - # return isis - - # # merge in default values - # isis = conf.merge_defaults(isis, recursive=True) - - # # We also need some additional information from the config, prefix-lists - # # and route-maps for instance. They will be used in verify(). - # # - # # XXX: one MUST always call this without the key_mangling() option! See - # # vyos.configverify.verify_common_route_maps() for more information. - # tmp = conf.get_config_dict(['policy']) - # # Merge policy dict into "regular" config dict - # isis = dict_merge(tmp, isis) - - return isis + return get_frrender_dict(conf, argv) def verify(config_dict): - global vrf - if not has_frr_protocol_in_dict(config_dict, 'isis', vrf): + if not has_frr_protocol_in_dict(config_dict, 'isis'): return None + vrf = None + if 'vrf_context' in config_dict: + vrf = config_dict['vrf_context'] + # eqivalent of the C foo ? 'a' : 'b' statement isis = vrf and config_dict['vrf']['name'][vrf]['protocols']['isis'] or config_dict['isis'] isis['policy'] = config_dict['policy'] @@ -96,9 +53,6 @@ def verify(config_dict): if 'deleted' in isis: return None - if vrf: - isis['vrf'] = vrf - if 'net' not in isis: raise ConfigError('Network entity is mandatory!') @@ -126,12 +80,11 @@ def verify(config_dict): f'Recommended area lsp-mtu {recom_area_mtu} or less ' \ '(calculated on MTU size).') - if 'vrf' in isis: + if vrf: # If interface specific options are set, we must ensure that the # interface is bound to our requesting VRF. Due to the VyOS # priorities the interface is bound to the VRF after creation of # the VRF itself, and before any routing protocol is configured. - vrf = isis['vrf'] tmp = get_interface_config(interface) if 'master' not in tmp or tmp['master'] != vrf: raise ConfigError(f'Interface "{interface}" is not a member of VRF "{vrf}"!') @@ -279,12 +232,12 @@ def verify(config_dict): return None def generate(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().generate(config_dict) return None def apply(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().apply() return None diff --git a/src/conf_mode/protocols_mpls.py b/src/conf_mode/protocols_mpls.py index 12899f0b2..bab9648c4 100755 --- a/src/conf_mode/protocols_mpls.py +++ b/src/conf_mode/protocols_mpls.py @@ -67,12 +67,12 @@ def verify(config_dict): return None def generate(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().generate(config_dict) return None def apply(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().apply() if not has_frr_protocol_in_dict(config_dict, 'mpls'): diff --git a/src/conf_mode/protocols_openfabric.py b/src/conf_mode/protocols_openfabric.py index 9fdcf4b50..48c89d742 100644 --- a/src/conf_mode/protocols_openfabric.py +++ b/src/conf_mode/protocols_openfabric.py @@ -89,12 +89,12 @@ def verify(config_dict): return None def generate(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().generate(config_dict) return None def apply(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().apply() return None diff --git a/src/conf_mode/protocols_ospf.py b/src/conf_mode/protocols_ospf.py index 07e6a5860..9d35aa007 100755 --- a/src/conf_mode/protocols_ospf.py +++ b/src/conf_mode/protocols_ospf.py @@ -31,23 +31,22 @@ from vyos import ConfigError from vyos import airbag airbag.enable() -vrf = None -if len(argv) > 1: - vrf = argv[1] - def get_config(config=None): if config: conf = config else: conf = Config() - return get_frrender_dict(conf) + return get_frrender_dict(conf, argv) def verify(config_dict): - global vrf - if not has_frr_protocol_in_dict(config_dict, 'ospf', vrf): + if not has_frr_protocol_in_dict(config_dict, 'ospf'): return None + vrf = None + if 'vrf_context' in config_dict: + vrf = config_dict['vrf_context'] + # eqivalent of the C foo ? 'a' : 'b' statement ospf = vrf and config_dict['vrf']['name'][vrf]['protocols']['ospf'] or config_dict['ospf'] ospf['policy'] = config_dict['policy'] @@ -177,12 +176,12 @@ def verify(config_dict): return None def generate(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().generate(config_dict) return None def apply(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().apply() return None diff --git a/src/conf_mode/protocols_ospfv3.py b/src/conf_mode/protocols_ospfv3.py index 9af85cabf..c6b042b54 100755 --- a/src/conf_mode/protocols_ospfv3.py +++ b/src/conf_mode/protocols_ospfv3.py @@ -31,23 +31,22 @@ from vyos import ConfigError from vyos import airbag airbag.enable() -vrf = None -if len(argv) > 1: - vrf = argv[1] - def get_config(config=None): if config: conf = config else: conf = Config() - return get_frrender_dict(conf) + return get_frrender_dict(conf, argv) def verify(config_dict): - global vrf - if not has_frr_protocol_in_dict(config_dict, 'ospfv3', vrf): + if not has_frr_protocol_in_dict(config_dict, 'ospfv3'): return None + vrf = None + if 'vrf_context' in config_dict: + vrf = config_dict['vrf_context'] + # eqivalent of the C foo ? 'a' : 'b' statement ospfv3 = vrf and config_dict['vrf']['name'][vrf]['protocols']['ospfv3'] or config_dict['ospfv3'] ospfv3['policy'] = config_dict['policy'] @@ -88,12 +87,12 @@ def verify(config_dict): return None def generate(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().generate(config_dict) return None def apply(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().apply() return None diff --git a/src/conf_mode/protocols_pim.py b/src/conf_mode/protocols_pim.py index df0e82d69..c40b9d86a 100755 --- a/src/conf_mode/protocols_pim.py +++ b/src/conf_mode/protocols_pim.py @@ -86,7 +86,7 @@ def verify(config_dict): unique.append(gr_addr) def generate(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().generate(config_dict) return None @@ -103,7 +103,7 @@ def apply(config_dict): if not pim_pid: call('/usr/lib/frr/pimd -d -F traditional --daemon -A 127.0.0.1') - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().apply() return None diff --git a/src/conf_mode/protocols_pim6.py b/src/conf_mode/protocols_pim6.py index a5d612814..ff8fa38c3 100755 --- a/src/conf_mode/protocols_pim6.py +++ b/src/conf_mode/protocols_pim6.py @@ -75,12 +75,12 @@ def verify(config_dict): unique.append(gr_addr) def generate(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().generate(config_dict) return None def apply(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().apply() return None diff --git a/src/conf_mode/protocols_rip.py b/src/conf_mode/protocols_rip.py index 7eb060504..38108c9f5 100755 --- a/src/conf_mode/protocols_rip.py +++ b/src/conf_mode/protocols_rip.py @@ -68,12 +68,12 @@ def verify(config_dict): f'with "split-horizon disable" for "{interface}"!') def generate(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().generate(config_dict) return None def apply(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().apply() return None diff --git a/src/conf_mode/protocols_ripng.py b/src/conf_mode/protocols_ripng.py index 5884e61f9..46f3ce014 100755 --- a/src/conf_mode/protocols_ripng.py +++ b/src/conf_mode/protocols_ripng.py @@ -68,12 +68,12 @@ def verify(config_dict): f'with "split-horizon disable" for "{interface}"!') def generate(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().generate(config_dict) return None def apply(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().apply() return None diff --git a/src/conf_mode/protocols_rpki.py b/src/conf_mode/protocols_rpki.py index 33696a742..d3f515feb 100755 --- a/src/conf_mode/protocols_rpki.py +++ b/src/conf_mode/protocols_rpki.py @@ -94,12 +94,12 @@ def generate(config_dict): write_file(cache_config['ssh']['public_key_file'], wrap_openssh_public_key(public_key_data, public_key_type)) write_file(cache_config['ssh']['private_key_file'], wrap_openssh_private_key(private_key_data)) - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().generate(config_dict) return None def apply(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().apply() return None diff --git a/src/conf_mode/protocols_segment-routing.py b/src/conf_mode/protocols_segment-routing.py index a776d1038..cc42e5ac7 100755 --- a/src/conf_mode/protocols_segment-routing.py +++ b/src/conf_mode/protocols_segment-routing.py @@ -54,7 +54,7 @@ def verify(config_dict): return None def generate(config_dict): - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().generate(config_dict) return None @@ -88,7 +88,7 @@ def apply(config_dict): else: sysctl_write(f'net.ipv6.conf.{interface}.seg6_enabled', '0') - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().apply() return None diff --git a/src/conf_mode/protocols_static.py b/src/conf_mode/protocols_static.py index 69500377c..29fa530f4 100755 --- a/src/conf_mode/protocols_static.py +++ b/src/conf_mode/protocols_static.py @@ -29,10 +29,6 @@ from vyos import ConfigError from vyos import airbag airbag.enable() -vrf = None -if len(argv) > 1: - vrf = argv[1] - config_file = '/etc/iproute2/rt_tables.d/vyos-static.conf' def get_config(config=None): @@ -41,13 +37,16 @@ def get_config(config=None): else: conf = Config() - return get_frrender_dict(conf) + return get_frrender_dict(conf, argv) def verify(config_dict): - global vrf - if not has_frr_protocol_in_dict(config_dict, 'static', vrf): + if not has_frr_protocol_in_dict(config_dict, 'static'): return None + vrf = None + if 'vrf_context' in config_dict: + vrf = config_dict['vrf_context'] + # eqivalent of the C foo ? 'a' : 'b' statement static = vrf and config_dict['vrf']['name'][vrf]['protocols']['static'] or config_dict['static'] static['policy'] = config_dict['policy'] @@ -82,22 +81,25 @@ def verify(config_dict): return None def generate(config_dict): - global vrf - if not has_frr_protocol_in_dict(config_dict, 'static', vrf): + if not has_frr_protocol_in_dict(config_dict, 'static'): return None + vrf = None + if 'vrf_context' in config_dict: + vrf = config_dict['vrf_context'] + # eqivalent of the C foo ? 'a' : 'b' statement static = vrf and config_dict['vrf']['name'][vrf]['protocols']['static'] or config_dict['static'] # Put routing table names in /etc/iproute2/rt_tables render(config_file, 'iproute2/static.conf.j2', static) - if 'frrender_cls' not in config_dict: + if config_dict and 'frrender_cls' not in config_dict: FRRender().generate(config_dict) return None -def apply(static): - if 'frrender_cls' not in config_dict: +def apply(config_dict): + if config_dict and 'frrender_cls' not in config_dict: FRRender().apply() return None diff --git a/src/services/vyos-configd b/src/services/vyos-configd index 21d91005a..ecad85801 100755 --- a/src/services/vyos-configd +++ b/src/services/vyos-configd @@ -331,7 +331,7 @@ if __name__ == '__main__': scripts_called = getattr(config, 'scripts_called', []) logger.debug(f'scripts_called: {scripts_called}') - if hasattr(config, 'frrender_cls'): + if hasattr(config, 'frrender_cls') and res == R_SUCCESS: frrender_cls = getattr(config, 'frrender_cls') frrender_cls.apply() else: |