mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix nxos_vpc idempotence issues (#25219)
* Fix nxos_vpc idempotence issues * Remove legacy-file pep8 now passing
This commit is contained in:
parent
80c1765653
commit
b76acc8ce8
2 changed files with 21 additions and 15 deletions
|
@ -147,10 +147,11 @@ changed:
|
||||||
sample: true
|
sample: true
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
from ansible.module_utils.nxos import load_config, run_commands
|
||||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
|
|
||||||
def execute_show_command(command, module, command_type='cli_show'):
|
def execute_show_command(command, module, command_type='cli_show'):
|
||||||
if module.params['transport'] == 'cli':
|
if module.params['transport'] == 'cli':
|
||||||
if "section" not in command:
|
if "section" not in command:
|
||||||
|
@ -158,7 +159,10 @@ def execute_show_command(command, module, command_type='cli_show'):
|
||||||
cmds = [command]
|
cmds = [command]
|
||||||
body = run_commands(module, cmds)
|
body = run_commands(module, cmds)
|
||||||
elif module.params['transport'] == 'nxapi':
|
elif module.params['transport'] == 'nxapi':
|
||||||
cmds = [command]
|
if command_type == 'cli_show_ascii':
|
||||||
|
cmds = [command]
|
||||||
|
else:
|
||||||
|
cmds = [command + ' | json']
|
||||||
body = run_commands(module, cmds)
|
body = run_commands(module, cmds)
|
||||||
return body
|
return body
|
||||||
|
|
||||||
|
@ -177,10 +181,9 @@ def get_vrf_list(module):
|
||||||
command = 'show vrf all'
|
command = 'show vrf all'
|
||||||
vrf_table = None
|
vrf_table = None
|
||||||
|
|
||||||
body = execute_show_command(command, module)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
vrf_table = body[0]['TABLE_vrf']['ROW_vrf']
|
body = execute_show_command(command, module)[0]
|
||||||
|
vrf_table = body['TABLE_vrf']['ROW_vrf']
|
||||||
except (KeyError, AttributeError):
|
except (KeyError, AttributeError):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
@ -219,7 +222,7 @@ def get_vpc(module):
|
||||||
if domain != 'not configured':
|
if domain != 'not configured':
|
||||||
delay_restore = None
|
delay_restore = None
|
||||||
pkl_src = None
|
pkl_src = None
|
||||||
role_priority = None
|
role_priority = '32667'
|
||||||
system_priority = None
|
system_priority = None
|
||||||
pkl_dest = None
|
pkl_dest = None
|
||||||
pkl_vrf = None
|
pkl_vrf = None
|
||||||
|
@ -249,7 +252,6 @@ def get_vpc(module):
|
||||||
if 'peer-gateway' in each:
|
if 'peer-gateway' in each:
|
||||||
peer_gw = True
|
peer_gw = True
|
||||||
|
|
||||||
|
|
||||||
command = 'show vpc peer-keepalive'
|
command = 'show vpc peer-keepalive'
|
||||||
body = execute_show_command(command, module)[0]
|
body = execute_show_command(command, module)[0]
|
||||||
|
|
||||||
|
@ -299,7 +301,7 @@ def get_commands_to_config_vpc(module, vpc, domain, existing):
|
||||||
pkl_dest = existing.get('pkl_dest')
|
pkl_dest = existing.get('pkl_dest')
|
||||||
if pkl_src and pkl_dest:
|
if pkl_src and pkl_dest:
|
||||||
pkl_command = ('peer-keepalive destination {0}'
|
pkl_command = ('peer-keepalive destination {0}'
|
||||||
' source {1} vrf {2}'.format(pkl_dest, pkl_src, pkl_vrf))
|
' source {1} vrf {2}'.format(pkl_dest, pkl_src, pkl_vrf))
|
||||||
commands.append(pkl_command)
|
commands.append(pkl_command)
|
||||||
|
|
||||||
if vpc.get('auto_recovery') is False:
|
if vpc.get('auto_recovery') is False:
|
||||||
|
@ -307,10 +309,16 @@ def get_commands_to_config_vpc(module, vpc, domain, existing):
|
||||||
else:
|
else:
|
||||||
vpc['auto_recovery'] = ''
|
vpc['auto_recovery'] = ''
|
||||||
|
|
||||||
if vpc.get('peer_gw') is False:
|
if 'peer_gw' in vpc:
|
||||||
vpc['peer_gw'] = 'no'
|
if vpc.get('peer_gw') is False:
|
||||||
|
vpc['peer_gw'] = 'no'
|
||||||
|
else:
|
||||||
|
vpc['peer_gw'] = ''
|
||||||
else:
|
else:
|
||||||
vpc['peer_gw'] = ''
|
if existing.get('peer_gw') is False:
|
||||||
|
vpc['peer_gw'] = 'no'
|
||||||
|
else:
|
||||||
|
vpc['peer_gw'] = ''
|
||||||
|
|
||||||
CONFIG_ARGS = {
|
CONFIG_ARGS = {
|
||||||
'role_priority': 'role priority {role_priority}',
|
'role_priority': 'role priority {role_priority}',
|
||||||
|
@ -318,7 +326,7 @@ def get_commands_to_config_vpc(module, vpc, domain, existing):
|
||||||
'delay_restore': 'delay restore {delay_restore}',
|
'delay_restore': 'delay restore {delay_restore}',
|
||||||
'peer_gw': '{peer_gw} peer-gateway',
|
'peer_gw': '{peer_gw} peer-gateway',
|
||||||
'auto_recovery': '{auto_recovery} auto-recovery',
|
'auto_recovery': '{auto_recovery} auto-recovery',
|
||||||
}
|
}
|
||||||
|
|
||||||
for param, value in vpc.items():
|
for param, value in vpc.items():
|
||||||
command = CONFIG_ARGS.get(param, 'DNE').format(**vpc)
|
command = CONFIG_ARGS.get(param, 'DNE').format(**vpc)
|
||||||
|
@ -359,7 +367,7 @@ def main():
|
||||||
argument_spec.update(nxos_argument_spec)
|
argument_spec.update(nxos_argument_spec)
|
||||||
|
|
||||||
module = AnsibleModule(argument_spec=argument_spec,
|
module = AnsibleModule(argument_spec=argument_spec,
|
||||||
supports_check_mode=True)
|
supports_check_mode=True)
|
||||||
|
|
||||||
warnings = list()
|
warnings = list()
|
||||||
check_args(module, warnings)
|
check_args(module, warnings)
|
||||||
|
@ -442,4 +450,3 @@ def main():
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
|
@ -401,7 +401,6 @@ lib/ansible/modules/network/nxos/nxos_system.py
|
||||||
lib/ansible/modules/network/nxos/nxos_udld.py
|
lib/ansible/modules/network/nxos/nxos_udld.py
|
||||||
lib/ansible/modules/network/nxos/nxos_udld_interface.py
|
lib/ansible/modules/network/nxos/nxos_udld_interface.py
|
||||||
lib/ansible/modules/network/nxos/nxos_user.py
|
lib/ansible/modules/network/nxos/nxos_user.py
|
||||||
lib/ansible/modules/network/nxos/nxos_vpc.py
|
|
||||||
lib/ansible/modules/network/nxos/nxos_vpc_interface.py
|
lib/ansible/modules/network/nxos/nxos_vpc_interface.py
|
||||||
lib/ansible/modules/network/nxos/nxos_vrf.py
|
lib/ansible/modules/network/nxos/nxos_vrf.py
|
||||||
lib/ansible/modules/network/nxos/nxos_vrf_interface.py
|
lib/ansible/modules/network/nxos/nxos_vrf_interface.py
|
||||||
|
|
Loading…
Reference in a new issue