Add vrf option to static routes (#55298)
* added vrf to static route * fix pylint errors * version added 2.9 for vrf * removed undocmented return values * Update README.rst
This commit is contained in:
parent
ea57377ddf
commit
6610d678f8
1 changed files with 38 additions and 5 deletions
|
@ -33,6 +33,11 @@ options:
|
|||
description:
|
||||
- Next hop IP of the static route.
|
||||
required: true
|
||||
vrf:
|
||||
description:
|
||||
- VRF for static route.
|
||||
default: default
|
||||
version_added: 2.9
|
||||
admin_distance:
|
||||
description:
|
||||
- Admin distance of the static route.
|
||||
|
@ -115,13 +120,20 @@ def map_obj_to_commands(updates, module):
|
|||
address = w['address']
|
||||
next_hop = w['next_hop']
|
||||
admin_distance = w['admin_distance']
|
||||
vrf = w['vrf']
|
||||
state = w['state']
|
||||
del w['state']
|
||||
|
||||
if state == 'absent' and w in have:
|
||||
commands.append('no ip route %s %s' % (address, next_hop))
|
||||
if vrf == 'default':
|
||||
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:
|
||||
commands.append('ip route %s %s %d' % (address, next_hop, admin_distance))
|
||||
if vrf == 'default':
|
||||
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
|
||||
|
||||
|
@ -145,7 +157,8 @@ def map_params_to_obj(module, required_together=None):
|
|||
'address': module.params['address'].strip(),
|
||||
'next_hop': module.params['next_hop'].strip(),
|
||||
'admin_distance': module.params['admin_distance'],
|
||||
'state': module.params['state']
|
||||
'state': module.params['state'],
|
||||
'vrf': module.params['vrf']
|
||||
})
|
||||
|
||||
return obj
|
||||
|
@ -164,22 +177,41 @@ def map_config_to_obj(module):
|
|||
obj = {}
|
||||
add_match = re.search(r'ip route ([\d\./]+)', line, re.M)
|
||||
if add_match:
|
||||
obj['vrf'] = 'default'
|
||||
address = add_match.group(1)
|
||||
if is_address(address):
|
||||
obj['address'] = address
|
||||
|
||||
hop_match = re.search(r'ip route {0} ([\d\./]+)'.format(address), line, re.M)
|
||||
if hop_match:
|
||||
hop = hop_match.group(1)
|
||||
if is_hop(hop):
|
||||
obj['next_hop'] = hop
|
||||
|
||||
dist_match = re.search(r'ip route {0} {1} (\d+)'.format(address, hop), line, re.M)
|
||||
if dist_match:
|
||||
distance = dist_match.group(1)
|
||||
obj['admin_distance'] = int(distance)
|
||||
else:
|
||||
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)
|
||||
|
||||
return objs
|
||||
|
@ -191,6 +223,7 @@ def main():
|
|||
element_spec = dict(
|
||||
address=dict(type='str', aliases=['prefix']),
|
||||
next_hop=dict(type='str'),
|
||||
vrf=dict(type='str', default='default'),
|
||||
admin_distance=dict(default=1, type='int'),
|
||||
state=dict(default='present', choices=['present', 'absent'])
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue