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:
Ganesh Nalawade 2018-06-29 15:07:38 +05:30 committed by GitHub
commit e41d427d1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 105 additions and 59 deletions

View file

@ -103,28 +103,21 @@ def run_commands(module, commands, check_rc=True):
responses = list()
connection = get_connection(module)
for cmd in to_list(commands):
try:
cmd = json.loads(cmd)
command = cmd['command']
prompt = cmd['prompt']
answer = cmd['answer']
except:
command = cmd
prompt = None
answer = None
try:
out = connection.get(command, prompt, answer)
except ConnectionError as exc:
try:
outputs = connection.run_commands(commands)
except ConnectionError as exc:
if check_rc:
module.fail_json(msg=to_text(exc))
else:
outputs = exc
for item in to_list(outputs):
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)))
module.fail_json(msg=u'Failed to decode output from %s: %s' % (item, to_text(item)))
responses.append(out)
responses.append(item)
return responses