|
|
|
@ -840,24 +840,30 @@ def get_existing(module, prefix, warnings):
|
|
|
|
|
parents = 'vrf context {0}'.format(module.params['vrf'])
|
|
|
|
|
prefix_to_regex = fix_prefix_to_regex(prefix)
|
|
|
|
|
|
|
|
|
|
route_regex = '.*ip\sroute\s{0}\s(?P<next_hop>\S+)(\sname\s(?P<route_name>\S+))?(\stag\s(?P<tag>\d+))?(\s(?P<pref>\d+)).*'.format(prefix_to_regex)
|
|
|
|
|
route_regex = ('.*ip\sroute\s{0}\s(?P<next_hop>\S+)(\sname\s(?P<route_name>\S+))?'
|
|
|
|
|
'(\stag\s(?P<tag>\d+))?(\s(?P<pref>\d+)).*'.format(prefix_to_regex))
|
|
|
|
|
|
|
|
|
|
if module.params['vrf'] == 'default':
|
|
|
|
|
config = str(netcfg)
|
|
|
|
|
else:
|
|
|
|
|
config = netcfg.get_section(parents)
|
|
|
|
|
try:
|
|
|
|
|
match_route = re.match(route_regex, config, re.DOTALL)
|
|
|
|
|
group_route = match_route.groupdict()
|
|
|
|
|
|
|
|
|
|
for key in key_map:
|
|
|
|
|
if key not in group_route.keys():
|
|
|
|
|
group_route['key'] = None
|
|
|
|
|
group_route['prefix'] = prefix
|
|
|
|
|
except (AttributeError, TypeError):
|
|
|
|
|
|
|
|
|
|
if config:
|
|
|
|
|
try:
|
|
|
|
|
match_route = re.match(route_regex, config, re.DOTALL)
|
|
|
|
|
group_route = match_route.groupdict()
|
|
|
|
|
|
|
|
|
|
for key in key_map:
|
|
|
|
|
if key not in group_route.keys():
|
|
|
|
|
group_route[key] = ''
|
|
|
|
|
group_route['prefix'] = prefix
|
|
|
|
|
group_route['vrf'] = module.params['vrf']
|
|
|
|
|
except (AttributeError, TypeError):
|
|
|
|
|
group_route = {}
|
|
|
|
|
else:
|
|
|
|
|
group_route = {}
|
|
|
|
|
if module.params['state'] == 'present':
|
|
|
|
|
msg = ("VRF {0} doesn't exist.".format(module.params['vrf']))
|
|
|
|
|
msg = ("VRF {0} didn't exist.".format(module.params['vrf']))
|
|
|
|
|
if msg not in warnings:
|
|
|
|
|
warnings.append(msg)
|
|
|
|
|
|
|
|
|
|
return group_route
|
|
|
|
|