mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 14:40:19 -07:00
[CLI_CONF] Refactor nxos module common library to use cliconf plugin (#31524)
* refactor nxos modules Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * get_config update * fix get_config * update nxos module * device_info * fix conflict * add failure message check * pep8 fixes * use get_capabilities to check cliconf * Add logic to detect platform in get_capabilities and cache in module_utils * return msg in edit_config * fix conflicts * make modules compatible * fix nxos cliconf api Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * cache capabilities * Update transport queries to get_capabilities in module level * fix unit tests * load_config error code * remove unnecessary change * Refactor nxos_install_os module
This commit is contained in:
parent
bd399ec674
commit
9f86b923e9
23 changed files with 220 additions and 132 deletions
|
@ -124,17 +124,19 @@ commands:
|
|||
'''
|
||||
|
||||
from ansible.module_utils.network.nxos.nxos import load_config, run_commands
|
||||
from ansible.module_utils.network.nxos.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.network.nxos.nxos import get_capabilities, nxos_argument_spec
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
def execute_show_command(command, module):
|
||||
provider = module.params['provider']
|
||||
if provider['transport'] == 'cli':
|
||||
device_info = get_capabilities(module)
|
||||
network_api = device_info.get('network_api', 'nxapi')
|
||||
|
||||
if network_api == 'cliconf':
|
||||
command += ' | json'
|
||||
cmds = [command]
|
||||
body = run_commands(module, cmds)
|
||||
elif provider['transport'] == 'nxapi':
|
||||
elif network_api == 'nxapi':
|
||||
cmds = [command]
|
||||
body = run_commands(module, cmds)
|
||||
|
||||
|
@ -382,7 +384,6 @@ def main():
|
|||
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
|
||||
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
results = dict(changed=False, warnings=warnings)
|
||||
|
||||
interface = module.params['interface'].lower()
|
||||
|
@ -395,7 +396,8 @@ def main():
|
|||
auth_type = module.params['auth_type']
|
||||
auth_string = module.params['auth_string']
|
||||
|
||||
transport = module.params['provider']['transport']
|
||||
device_info = get_capabilities(module)
|
||||
network_api = device_info.get('network_api', 'nxapi')
|
||||
|
||||
if state == 'present' and not vip:
|
||||
module.fail_json(msg='the "vip" param is required when state=present')
|
||||
|
@ -405,7 +407,7 @@ def main():
|
|||
validate_params(param, module)
|
||||
|
||||
intf_type = get_interface_type(interface)
|
||||
if (intf_type != 'ethernet' and transport == 'cli'):
|
||||
if (intf_type != 'ethernet' and network_api == 'cliconf'):
|
||||
if is_default(interface, module) == 'DNE':
|
||||
module.fail_json(msg='That interface does not exist yet. Create '
|
||||
'it first.', interface=interface)
|
||||
|
@ -463,7 +465,7 @@ def main():
|
|||
load_config(module, commands)
|
||||
|
||||
# validate IP
|
||||
if transport == 'cli' and state == 'present':
|
||||
if network_api == 'cliconf' and state == 'present':
|
||||
commands.insert(0, 'config t')
|
||||
body = run_commands(module, commands)
|
||||
validate_config(body, vip, module)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue