From ee02d6c2c1d2d8641a20e18cdb847a4129429c08 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sat, 7 Mar 2020 09:48:32 +0100 Subject: vrf: T31: reuse Config in interfaces_with_vrf() --- src/conf_mode/vrf.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/conf_mode') diff --git a/src/conf_mode/vrf.py b/src/conf_mode/vrf.py index 623b7f216..db546956b 100755 --- a/src/conf_mode/vrf.py +++ b/src/conf_mode/vrf.py @@ -61,10 +61,11 @@ def list_rules(): answer = loads(check_output(command.split()).decode()) return [_ for _ in answer if _] -def interfaces_with_vrf(match): +def interfaces_with_vrf(c, match): matched = [] - config = Config() - section = config.get_config_dict('interfaces') + old_level = c.get_level() + c.set_level(['interfaces']) + section = c.get_config_dict([]) for type in section: interfaces = section[type] for name in interfaces: @@ -73,6 +74,8 @@ def interfaces_with_vrf(match): v = interface.get('vrf', '') if v == match: matched.append(name) + + c.set_level(old_level) return matched def get_config(): @@ -122,7 +125,7 @@ def get_config(): vrf_inst['description'] = conf.return_value(['description']) # find member interfaces of this particulat VRF - vrf_inst['members'] = interfaces_with_vrf(name) + vrf_inst['members'] = interfaces_with_vrf(conf, name) # append individual VRF configuration to global configuration list vrf_config['vrf_add'].append(vrf_inst) @@ -140,7 +143,7 @@ def get_config(): } # find member interfaces of this particulat VRF - vrf_inst['members'] = interfaces_with_vrf(name) + vrf_inst['members'] = interfaces_with_vrf(conf, name) # append individual VRF configuration to temporary configuration list tmp.append(vrf_inst) -- cgit v1.2.3