Coverage for lib/ansible/modules/network/nxos/nxos_static_route.py : 73%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/python # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>. # 'status': ['preview'], 'supported_by': 'network'}
--- module: nxos_static_route extends_documentation_fragment: nxos version_added: "2.2" short_description: Manages static route configuration description: - Manages static route configuration author: Gabriele Gerbino (@GGabriele) notes: - Tested against NXOSv 7.3.(0)D1(1) on VIRL - If no vrf is supplied, vrf is set to default. - If C(state=absent), the route will be removed, regardless of the non-required parameters. options: prefix: description: - Destination prefix of static route. required: true aliases: - address next_hop: description: - Next hop address or interface of static route. If interface, it must be the fully-qualified interface name. required: true vrf: description: - VRF for static route. required: false default: default tag: description: - Route tag value (numeric). required: false default: null route_name: description: - Name of the route. Used with the name parameter on the CLI. required: false default: null pref: description: - Preference or administrative difference of route (range 1-255). required: false default: null aliases: - admin_distance aggregate: description: List of static route definitions version_added: 2.5 state: description: - Manage the state of the resource. required: true choices: ['present','absent'] '''
- nxos_static_route: prefix: "192.168.20.64/24" next_hop: "3.3.3.3" route_name: testing pref: 100 '''
commands: description: commands sent to the device returned: always type: list sample: ["ip route 192.168.20.0/24 3.3.3.3 name testing 100"] '''
commands = [remove_command] commands = [set_command] else:
prefix = prefix.replace('.', r'\.').replace('/', r'\/') return prefix
key_map = ['tag', 'pref', 'route_name', 'next_hop'] netcfg = CustomNetworkConfig(indent=2, contents=get_config(module)) parents = 'vrf context {0}'.format(module.params['vrf']) prefix_to_regex = fix_prefix_to_regex(prefix)
route_regex = r'.*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)
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: group_route[key] = '' group_route['prefix'] = prefix group_route['vrf'] = module.params['vrf'] except (AttributeError, TypeError): group_route = {} else: group_route = {} msg = ("VRF {0} didn't exist.".format(module.params['vrf'])) if msg not in warnings: warnings.append(msg)
return group_route
module.fail_json(msg='Incorrect address format.', address=address)
module.fail_json(msg='Address may contain invalid values.', address=address) except ValueError: module.fail_json(msg='Address may contain non-integer values.', address=address)
module.fail_json(msg='Incorrect mask value.', mask=mask) except ValueError: module.fail_json(msg='Mask may contain non-integer values.', mask=mask)
module.fail_json(msg='Incorrect address format.', address=address)
else: normalized_prefix = prefix + '/' + str(32)
else: 'prefix': module.params['prefix'], 'next_hop': module.params['next_hop'], 'vrf': module.params['vrf'], 'tag': module.params['tag'], 'route_name': module.params['route_name'], 'pref': module.params['pref'], 'state': module.params['state'] })
prefix=dict(type='str', aliases=['address']), next_hop=dict(type='str'), vrf=dict(type='str', default='default'), tag=dict(type='str'), route_name=dict(type='str'), pref=dict(type='str', aliases=['admin_distance']), state=dict(choices=['absent', 'present'], default='present'), )
# remove default in aggregate spec, to handle common arguments
aggregate=dict(type='list', elements='dict', options=aggregate_spec) )
argument_spec=argument_spec, supports_check_mode=True, )
result['warnings'] = warnings
else:
|