|
|
@ -33,6 +33,11 @@ options:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Next hop IP of the static route.
|
|
|
|
- Next hop IP of the static route.
|
|
|
|
required: true
|
|
|
|
required: true
|
|
|
|
|
|
|
|
vrf:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- VRF for static route.
|
|
|
|
|
|
|
|
default: default
|
|
|
|
|
|
|
|
version_added: 2.9
|
|
|
|
admin_distance:
|
|
|
|
admin_distance:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Admin distance of the static route.
|
|
|
|
- Admin distance of the static route.
|
|
|
@ -115,13 +120,20 @@ def map_obj_to_commands(updates, module):
|
|
|
|
address = w['address']
|
|
|
|
address = w['address']
|
|
|
|
next_hop = w['next_hop']
|
|
|
|
next_hop = w['next_hop']
|
|
|
|
admin_distance = w['admin_distance']
|
|
|
|
admin_distance = w['admin_distance']
|
|
|
|
|
|
|
|
vrf = w['vrf']
|
|
|
|
state = w['state']
|
|
|
|
state = w['state']
|
|
|
|
del w['state']
|
|
|
|
del w['state']
|
|
|
|
|
|
|
|
|
|
|
|
if state == 'absent' and w in have:
|
|
|
|
if state == 'absent' and w in have:
|
|
|
|
|
|
|
|
if vrf == 'default':
|
|
|
|
commands.append('no ip route %s %s' % (address, next_hop))
|
|
|
|
commands.append('no ip route %s %s' % (address, next_hop))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
commands.append('no ip route vrf %s %s %s' % (vrf, address, next_hop))
|
|
|
|
elif state == 'present' and w not in have:
|
|
|
|
elif state == 'present' and w not in have:
|
|
|
|
|
|
|
|
if vrf == 'default':
|
|
|
|
commands.append('ip route %s %s %d' % (address, next_hop, admin_distance))
|
|
|
|
commands.append('ip route %s %s %d' % (address, next_hop, admin_distance))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
commands.append('ip route vrf %s %s %s %d' % (vrf, address, next_hop, admin_distance))
|
|
|
|
|
|
|
|
|
|
|
|
return commands
|
|
|
|
return commands
|
|
|
|
|
|
|
|
|
|
|
@ -145,7 +157,8 @@ def map_params_to_obj(module, required_together=None):
|
|
|
|
'address': module.params['address'].strip(),
|
|
|
|
'address': module.params['address'].strip(),
|
|
|
|
'next_hop': module.params['next_hop'].strip(),
|
|
|
|
'next_hop': module.params['next_hop'].strip(),
|
|
|
|
'admin_distance': module.params['admin_distance'],
|
|
|
|
'admin_distance': module.params['admin_distance'],
|
|
|
|
'state': module.params['state']
|
|
|
|
'state': module.params['state'],
|
|
|
|
|
|
|
|
'vrf': module.params['vrf']
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
return obj
|
|
|
|
return obj
|
|
|
@ -164,22 +177,41 @@ def map_config_to_obj(module):
|
|
|
|
obj = {}
|
|
|
|
obj = {}
|
|
|
|
add_match = re.search(r'ip route ([\d\./]+)', line, re.M)
|
|
|
|
add_match = re.search(r'ip route ([\d\./]+)', line, re.M)
|
|
|
|
if add_match:
|
|
|
|
if add_match:
|
|
|
|
|
|
|
|
obj['vrf'] = 'default'
|
|
|
|
address = add_match.group(1)
|
|
|
|
address = add_match.group(1)
|
|
|
|
if is_address(address):
|
|
|
|
if is_address(address):
|
|
|
|
obj['address'] = address
|
|
|
|
obj['address'] = address
|
|
|
|
|
|
|
|
|
|
|
|
hop_match = re.search(r'ip route {0} ([\d\./]+)'.format(address), line, re.M)
|
|
|
|
hop_match = re.search(r'ip route {0} ([\d\./]+)'.format(address), line, re.M)
|
|
|
|
if hop_match:
|
|
|
|
if hop_match:
|
|
|
|
hop = hop_match.group(1)
|
|
|
|
hop = hop_match.group(1)
|
|
|
|
if is_hop(hop):
|
|
|
|
if is_hop(hop):
|
|
|
|
obj['next_hop'] = hop
|
|
|
|
obj['next_hop'] = hop
|
|
|
|
|
|
|
|
|
|
|
|
dist_match = re.search(r'ip route {0} {1} (\d+)'.format(address, hop), line, re.M)
|
|
|
|
dist_match = re.search(r'ip route {0} {1} (\d+)'.format(address, hop), line, re.M)
|
|
|
|
if dist_match:
|
|
|
|
if dist_match:
|
|
|
|
distance = dist_match.group(1)
|
|
|
|
distance = dist_match.group(1)
|
|
|
|
obj['admin_distance'] = int(distance)
|
|
|
|
obj['admin_distance'] = int(distance)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
obj['admin_distance'] = 1
|
|
|
|
obj['admin_distance'] = 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vrf_match = re.search(r'ip route vrf ([\w]+) ([\d\./]+)', line, re.M)
|
|
|
|
|
|
|
|
if vrf_match:
|
|
|
|
|
|
|
|
vrf = vrf_match.group(1)
|
|
|
|
|
|
|
|
obj['vrf'] = vrf
|
|
|
|
|
|
|
|
address = vrf_match.group(2)
|
|
|
|
|
|
|
|
if is_address(address):
|
|
|
|
|
|
|
|
obj['address'] = address
|
|
|
|
|
|
|
|
hop_vrf_match = re.search(r'ip route vrf {0} {1} ([\d\./]+)'.format(vrf, address), line, re.M)
|
|
|
|
|
|
|
|
if hop_vrf_match:
|
|
|
|
|
|
|
|
hop = hop_vrf_match.group(1)
|
|
|
|
|
|
|
|
if is_hop(hop):
|
|
|
|
|
|
|
|
obj['next_hop'] = hop
|
|
|
|
|
|
|
|
dist_vrf_match = re.search(r'ip route vrf {0} {1} {2} (\d+)'.format(vrf, address, hop), line, re.M)
|
|
|
|
|
|
|
|
if dist_vrf_match:
|
|
|
|
|
|
|
|
distance = dist_vrf_match.group(1)
|
|
|
|
|
|
|
|
obj['admin_distance'] = int(distance)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
obj['admin_distance'] = 1
|
|
|
|
|
|
|
|
|
|
|
|
objs.append(obj)
|
|
|
|
objs.append(obj)
|
|
|
|
|
|
|
|
|
|
|
|
return objs
|
|
|
|
return objs
|
|
|
@ -191,6 +223,7 @@ def main():
|
|
|
|
element_spec = dict(
|
|
|
|
element_spec = dict(
|
|
|
|
address=dict(type='str', aliases=['prefix']),
|
|
|
|
address=dict(type='str', aliases=['prefix']),
|
|
|
|
next_hop=dict(type='str'),
|
|
|
|
next_hop=dict(type='str'),
|
|
|
|
|
|
|
|
vrf=dict(type='str', default='default'),
|
|
|
|
admin_distance=dict(default=1, type='int'),
|
|
|
|
admin_distance=dict(default=1, type='int'),
|
|
|
|
state=dict(default='present', choices=['present', 'absent'])
|
|
|
|
state=dict(default='present', choices=['present', 'absent'])
|
|
|
|
)
|
|
|
|
)
|
|
|
|