From 49f692b08f2a5d8ef3588be0e9931683a342f9bd Mon Sep 17 00:00:00 2001 From: Dennis Israelsson Date: Mon, 27 Aug 2018 14:51:33 +0200 Subject: [PATCH] ios_vrf speed fix (#43765) --- lib/ansible/modules/network/ios/ios_vrf.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/ansible/modules/network/ios/ios_vrf.py b/lib/ansible/modules/network/ios/ios_vrf.py index 9d01ff4de02..e7173237d49 100644 --- a/lib/ansible/modules/network/ios/ios_vrf.py +++ b/lib/ansible/modules/network/ios/ios_vrf.py @@ -405,12 +405,16 @@ def parse_rd(configobj, name): return match.group(1) -def parse_interfaces(configobj, name): - vrf_cfg = 'vrf forwarding %s' % name - interfaces = list() - for intf in re.findall('^interface .+', str(configobj), re.M): - if vrf_cfg in '\n'.join(configobj[intf].children): - interfaces.append(intf.split(' ')[1]) +def parse_interfaces(configobj): + vrf_cfg = 'vrf forwarding' + interfaces = dict() + for intf in set(re.findall('^interface .+', str(configobj), re.M)): + for line in configobj[intf].children: + if vrf_cfg in line: + try: + interfaces[line.split()[-1]].append(intf.split(' ')[1]) + except KeyError: + interfaces[line.split()[-1]] = [intf.split(' ')[1]] return interfaces @@ -507,13 +511,16 @@ def map_config_to_obj(module): return list() instances = list() + + interfaces = parse_interfaces(configobj) + for item in set(match): obj = { 'name': item, 'state': 'present', 'description': parse_description(configobj, item), 'rd': parse_rd(configobj, item), - 'interfaces': parse_interfaces(configobj, item), + 'interfaces': interfaces.get(item), 'route_import': parse_import(configobj, item), 'route_export': parse_export(configobj, item), 'route_both': parse_both(configobj, item),