mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Nxos vxlan vtep vni netcfg fix (#23620)
* Code cleanup Removed 'add' method from CustomNetworkConfig. It is identical to the one inherited from NetworkConfig * Removed unused CustomNetworkConfig import * Replaced ``` def get_existing(module, args): existing = {} netcfg = get_config(module) config = netcfg.get_section(parents) ``` with ``` netcfg = CustomNetworkConfig(indent=2, contents=get_config(module)) ``` get_config returns a string, not an object in 2.3. * Removed non-functioning get_object method in CustomNetworkConfig in favor of the inherited method. Added child_objs property so that expand_selection would work. The original verion never worked correctly as it compared NetworkConfig obj's and str's. * Removed ShellError method in favor or new load_config method. * Removed ShellError method in favor or new load_config method. fixes #20260 * nxos requires a "no" statement to change mcase group. Corrected. Corrected changed logic. * Corrected deleted CustomNetworkConfig import
This commit is contained in:
parent
e518b6f5b4
commit
bbb9f3164c
44 changed files with 35 additions and 112 deletions
|
@ -549,7 +549,7 @@ def get_value(arg, config):
|
|||
|
||||
def get_existing(module, args):
|
||||
existing = {}
|
||||
netcfg = get_config(module)
|
||||
netcfg = CustomNetworkConfig(indent=2, contents=get_config(module))
|
||||
|
||||
try:
|
||||
asn_regex = '.*router\sbgp\s(?P<existing_asn>\d+).*'
|
||||
|
|
|
@ -539,7 +539,7 @@ def get_value(arg, config, module):
|
|||
|
||||
def get_existing(module, args):
|
||||
existing = {}
|
||||
netcfg = get_config(module)
|
||||
netcfg = CustomNetworkConfig(indent=2, contents=get_config(module))
|
||||
|
||||
try:
|
||||
asn_regex = '.*router\sbgp\s(?P<existing_asn>\d+).*'
|
||||
|
|
|
@ -372,7 +372,7 @@ def get_custom_value(arg, config, module):
|
|||
|
||||
def get_existing(module, args):
|
||||
existing = {}
|
||||
netcfg = get_config(module)
|
||||
netcfg = CustomNetworkConfig(indent=2, contents=get_config(module))
|
||||
custom = [
|
||||
'log_neighbor_changes',
|
||||
'pwd',
|
||||
|
|
|
@ -503,7 +503,7 @@ def get_custom_value(arg, config, module):
|
|||
|
||||
def get_existing(module, args):
|
||||
existing = {}
|
||||
netcfg = get_config(module)
|
||||
netcfg = CustomNetworkConfig(indent=2, contents=get_config(module))
|
||||
|
||||
custom = [
|
||||
'allowas_in_max',
|
||||
|
|
|
@ -174,7 +174,7 @@ def get_route_target_value(arg, config, module):
|
|||
|
||||
def get_existing(module, args):
|
||||
existing = {}
|
||||
netcfg = get_config(module)
|
||||
netcfg = CustomNetworkConfig(indent=2, contents=get_config(module))
|
||||
parents = ['evpn', 'vni {0} l2'.format(module.params['vni'])]
|
||||
config = netcfg.get_section(parents)
|
||||
|
||||
|
|
|
@ -166,7 +166,6 @@ import re
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
def execute_show_command(command, module, command_type='cli_show_ascii'):
|
||||
cmds = [command]
|
||||
|
|
|
@ -127,7 +127,7 @@ from ansible.module_utils.netcfg import CustomNetworkConfig
|
|||
|
||||
def get_existing(module):
|
||||
existing = []
|
||||
netcfg = get_config(module)
|
||||
netcfg = CustomNetworkConfig(indent=2, contents=get_config(module))
|
||||
|
||||
if module.params['mode'] == 'maintenance':
|
||||
parents = ['configure maintenance profile maintenance-mode']
|
||||
|
|
|
@ -148,7 +148,6 @@ changed:
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -238,7 +238,6 @@ changed:
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
import re
|
||||
|
||||
|
|
|
@ -134,7 +134,6 @@ changed:
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
import re
|
||||
|
||||
|
|
|
@ -122,7 +122,6 @@ import re
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
|
||||
def execute_show_command(command, module, command_type='cli_show_ascii'):
|
||||
|
|
|
@ -169,7 +169,6 @@ changed:
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -281,7 +281,7 @@ def get_value(arg, config, module):
|
|||
|
||||
def get_existing(module, args):
|
||||
existing = {}
|
||||
netcfg = get_config(module)
|
||||
netcfg = CustomNetworkConfig(indent=2, contents=get_config(module))
|
||||
parents = ['interface {0}'.format(module.params['interface'].capitalize())]
|
||||
config = netcfg.get_section(parents)
|
||||
if 'ospf' in config:
|
||||
|
|
|
@ -116,7 +116,6 @@ changed:
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
import re
|
||||
|
||||
|
|
|
@ -130,7 +130,6 @@ changed:
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
import re
|
||||
|
||||
|
|
|
@ -128,7 +128,6 @@ changed:
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
import re
|
||||
|
||||
|
|
|
@ -109,7 +109,6 @@ changed:
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
|
||||
import re
|
||||
|
|
|
@ -239,7 +239,7 @@ def get_value(arg, config, module):
|
|||
|
||||
def get_existing(module, args):
|
||||
existing = {}
|
||||
netcfg = get_config(module)
|
||||
netcfg = CustomNetworkConfig(indent=2, contents=get_config(module))
|
||||
parents = ['router ospf {0}'.format(module.params['ospf'])]
|
||||
|
||||
if module.params['vrf'] != 'default':
|
||||
|
|
|
@ -192,7 +192,6 @@ changed:
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
import time
|
||||
|
||||
|
|
|
@ -207,7 +207,7 @@ def get_portchannel_mode(interface, protocol, module, netcfg):
|
|||
if protocol != 'LACP':
|
||||
mode = 'on'
|
||||
else:
|
||||
netcfg = get_config(module)
|
||||
netcfg = CustomNetworkConfig(indent=2, contents=get_config(module))
|
||||
parents = ['interface {0}'.format(interface.capitalize())]
|
||||
body = netcfg.get_section(parents)
|
||||
|
||||
|
@ -281,7 +281,7 @@ def get_portchannel(module, netcfg=None):
|
|||
|
||||
def get_existing(module, args):
|
||||
existing = {}
|
||||
netcfg = get_config(module)
|
||||
netcfg = CustomNetworkConfig(indent=2, contents=get_config(module))
|
||||
|
||||
interface_exist = check_interface(module, netcfg)
|
||||
if interface_exist:
|
||||
|
|
|
@ -81,7 +81,6 @@ status:
|
|||
from ansible.module_utils.nxos import nxos_argument_spec, run_commands
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
def checkpoint(filename, module):
|
||||
commands = ['terminal dont-ask', 'checkpoint file %s' % filename]
|
||||
run_commands(module, commands)
|
||||
|
|
|
@ -84,7 +84,6 @@ changed:
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
import time
|
||||
import collections
|
||||
|
|
|
@ -103,7 +103,6 @@ changed:
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
|
||||
import re
|
||||
|
|
|
@ -88,7 +88,6 @@ changed:
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
|
||||
import re
|
||||
|
|
|
@ -136,7 +136,6 @@ changed:
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
|
||||
import re
|
||||
|
|
|
@ -95,7 +95,6 @@ changed:
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
|
||||
import re
|
||||
|
|
|
@ -106,7 +106,6 @@ changed:
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
|
||||
import re
|
||||
|
|
|
@ -117,7 +117,6 @@ changed:
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
|
||||
import re
|
||||
|
|
|
@ -136,7 +136,7 @@ def state_present(module, candidate, prefix):
|
|||
|
||||
|
||||
def state_absent(module, candidate, prefix):
|
||||
netcfg = get_config(module)
|
||||
netcfg = CustomNetworkConfig(indent=2, contents=get_config(module))
|
||||
commands = list()
|
||||
parents = 'vrf context {0}'.format(module.params['vrf'])
|
||||
invoke('set_route', module, commands, prefix)
|
||||
|
@ -161,7 +161,7 @@ def fix_prefix_to_regex(prefix):
|
|||
|
||||
def get_existing(module, prefix, warnings):
|
||||
key_map = ['tag', 'pref', 'route_name', 'next_hop']
|
||||
netcfg = get_config(module)
|
||||
netcfg = CustomNetworkConfig(indent=2, contents=get_config(module))
|
||||
parents = 'vrf context {0}'.format(module.params['vrf'])
|
||||
prefix_to_regex = fix_prefix_to_regex(prefix)
|
||||
|
||||
|
|
|
@ -159,7 +159,6 @@ changed:
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
|
||||
import re
|
||||
|
|
|
@ -113,7 +113,6 @@ changed:
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
|
||||
import re
|
||||
|
|
|
@ -112,7 +112,6 @@ changed:
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
|
||||
import re
|
||||
|
|
|
@ -150,7 +150,6 @@ changed:
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
def execute_show_command(command, module, command_type='cli_show'):
|
||||
if module.params['transport'] == 'cli':
|
||||
|
|
|
@ -102,7 +102,6 @@ changed:
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
def execute_show_command(command, module, command_type='cli_show'):
|
||||
if module.params['transport'] == 'cli':
|
||||
|
|
|
@ -124,7 +124,6 @@ import re
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
def execute_show_command(command, module, command_type='cli_show'):
|
||||
transport = module.params['provider']['transport']
|
||||
|
|
|
@ -144,7 +144,7 @@ def get_value(arg, config, module):
|
|||
|
||||
def get_existing(module, args):
|
||||
existing = {}
|
||||
netcfg = get_config(module)
|
||||
netcfg = CustomNetworkConfig(indent=2, contents=get_config(module))
|
||||
|
||||
parents = ['vrf context {0}'.format(module.params['vrf'])]
|
||||
parents.append('address-family {0} {1}'.format(module.params['afi'],
|
||||
|
|
|
@ -104,7 +104,6 @@ import re
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
|
||||
WARNINGS = []
|
||||
|
|
|
@ -142,7 +142,6 @@ import re
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
def execute_show_command(command, module, command_type='cli_show'):
|
||||
if module.params['transport'] == 'cli':
|
||||
|
|
|
@ -89,7 +89,6 @@ changed:
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
import re
|
||||
|
||||
|
||||
|
|
|
@ -106,7 +106,6 @@ changed:
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
import re
|
||||
|
||||
|
||||
|
|
|
@ -84,7 +84,6 @@ changed:
|
|||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
||||
|
||||
import re
|
||||
|
|
|
@ -202,7 +202,7 @@ def get_value(arg, config, module):
|
|||
|
||||
def get_existing(module, args):
|
||||
existing = {}
|
||||
netcfg = get_config(module)
|
||||
netcfg = CustomNetworkConfig(indent=2, contents=get_config(module))
|
||||
|
||||
interface_string = 'interface {0}'.format(module.params['interface'].lower())
|
||||
parents = [interface_string]
|
||||
|
|
|
@ -217,7 +217,7 @@ def get_custom_value(arg, config, module):
|
|||
|
||||
def get_existing(module, args):
|
||||
existing = {}
|
||||
netcfg = get_config(module)
|
||||
netcfg = CustomNetworkConfig(indent=2, contents=get_config(module))
|
||||
|
||||
custom = [
|
||||
'assoc_vrf',
|
||||
|
@ -283,6 +283,10 @@ def state_present(module, existing, proposed, candidate):
|
|||
for peer in value:
|
||||
commands.append('{0} {1}'.format(key, peer))
|
||||
|
||||
elif key == 'mcast-group' and value != existing_commands.get(key):
|
||||
commands.append('no {0}'.format(key))
|
||||
commands.append('{0} {1}'.format(key, value))
|
||||
|
||||
elif value is True:
|
||||
commands.append(key)
|
||||
|
||||
|
@ -422,13 +426,17 @@ def main():
|
|||
else:
|
||||
candidate = CustomNetworkConfig(indent=3)
|
||||
invoke('state_%s' % state, module, existing, proposed, candidate)
|
||||
|
||||
try:
|
||||
response = load_config(module, candidate)
|
||||
result.update(response)
|
||||
except ShellError:
|
||||
exc = get_exception()
|
||||
module.fail_json(msg=str(exc))
|
||||
result['changed'] = False
|
||||
for k, v in proposed.items():
|
||||
if k in existing:
|
||||
if existing[k] != proposed[k] or state == 'absent':
|
||||
result['changed'] = True
|
||||
if k not in existing and state == 'present':
|
||||
result['changed'] = True
|
||||
if module.check_mode:
|
||||
module.exit_json(commands=candidate)
|
||||
else:
|
||||
load_config(module, candidate)
|
||||
else:
|
||||
result['updates'] = []
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue