mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 14:22:46 +00:00
HTTP(S) API connection plugin (#39224)
* HTTPAPI connection * Punt run_commands to cliconf or httpapi * Fake enable_mode on eapi * Pull changes to nxos * Move load_config to edit_config for future-preparedness * Don't fail on lldp disabled * Re-enable check_rc on nxos' run_commands * Reorganize nxos httpapi plugin for compatibility * draft docs for connection: httpapi * restores docs for connection:local for eapi * Add _remote_is_local to httpapi
This commit is contained in:
@@ -146,47 +146,8 @@ class Cli:
|
||||
def run_commands(self, commands, check_rc=True):
|
||||
"""Run list of commands on remote device and return results
|
||||
"""
|
||||
responses = list()
|
||||
connection = self._get_connection()
|
||||
|
||||
for item in to_list(commands):
|
||||
if item['output'] == 'json' and not is_json(item['command']):
|
||||
cmd = '%s | json' % item['command']
|
||||
elif item['output'] == 'text' and is_json(item['command']):
|
||||
cmd = item['command'].rsplit('|', 1)[0]
|
||||
else:
|
||||
cmd = item['command']
|
||||
|
||||
out = ''
|
||||
try:
|
||||
out = connection.get(cmd)
|
||||
code = 0
|
||||
except ConnectionError as e:
|
||||
code = getattr(e, 'code', 1)
|
||||
message = getattr(e, 'err', e)
|
||||
err = to_text(message, errors='surrogate_then_replace')
|
||||
|
||||
try:
|
||||
out = to_text(out, errors='surrogate_or_strict')
|
||||
except UnicodeError:
|
||||
self._module.fail_json(msg=u'Failed to decode output from %s: %s' % (cmd, to_text(out)))
|
||||
|
||||
if check_rc and code != 0:
|
||||
self._module.fail_json(msg=err)
|
||||
|
||||
if not check_rc and code != 0:
|
||||
try:
|
||||
out = self._module.from_json(err)
|
||||
except ValueError:
|
||||
out = to_text(message).strip()
|
||||
else:
|
||||
try:
|
||||
out = self._module.from_json(out)
|
||||
except ValueError:
|
||||
out = to_text(out).strip()
|
||||
|
||||
responses.append(out)
|
||||
return responses
|
||||
return connection.run_commands(commands, check_rc)
|
||||
|
||||
def load_config(self, config, return_error=False, opts=None):
|
||||
"""Sends configuration commands to the remote device
|
||||
|
||||
Reference in New Issue
Block a user