mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 22:30:22 -07:00
Add run_commands api for ios and vyos cliconf plugin (#42093)
* Add run_commands api for ios and vyos cliconf plugin * Add run_commands api to ios and vyos cliconf plugin * Refactor ios and vyos module_utils to check return code in run_commands * Fix Ci failures
This commit is contained in:
parent
956320ba5d
commit
e41d427d1b
7 changed files with 105 additions and 59 deletions
|
@ -134,31 +134,21 @@ def run_commands(module, commands, check_rc=True):
|
|||
responses = list()
|
||||
connection = get_connection(module)
|
||||
|
||||
for cmd in to_list(commands):
|
||||
if isinstance(cmd, dict):
|
||||
command = cmd['command']
|
||||
prompt = cmd['prompt']
|
||||
answer = cmd['answer']
|
||||
try:
|
||||
outputs = connection.run_commands(commands)
|
||||
except ConnectionError as exc:
|
||||
if check_rc:
|
||||
module.fail_json(msg=to_text(exc))
|
||||
else:
|
||||
command = cmd
|
||||
prompt = None
|
||||
answer = None
|
||||
outputs = exc
|
||||
|
||||
for item in to_list(outputs):
|
||||
try:
|
||||
out = connection.get(command, prompt, answer)
|
||||
except ConnectionError as exc:
|
||||
if check_rc:
|
||||
module.fail_json(msg=to_text(exc))
|
||||
else:
|
||||
out = exc
|
||||
|
||||
try:
|
||||
out = to_text(out, errors='surrogate_or_strict')
|
||||
item = to_text(item, errors='surrogate_or_strict')
|
||||
except UnicodeError:
|
||||
module.fail_json(msg=u'Failed to decode output from %s: %s' % (cmd, to_text(out)))
|
||||
|
||||
responses.append(out)
|
||||
module.fail_json(msg=u'Failed to decode output from %s: %s' % (item, to_text(item)))
|
||||
|
||||
responses.append(item)
|
||||
return responses
|
||||
|
||||
|
||||
|
@ -167,7 +157,6 @@ def load_config(module, commands):
|
|||
|
||||
try:
|
||||
resp = connection.edit_config(commands)
|
||||
resp = json.loads(resp)
|
||||
return resp.get('response')
|
||||
except ConnectionError as exc:
|
||||
module.fail_json(msg=to_text(exc))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue