mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +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:
@@ -163,46 +163,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 cmd in to_list(commands):
|
||||
if isinstance(cmd, dict):
|
||||
command = cmd['command']
|
||||
prompt = cmd['prompt']
|
||||
answer = cmd['answer']
|
||||
else:
|
||||
command = cmd
|
||||
prompt = None
|
||||
answer = None
|
||||
|
||||
out = connection.get(command, prompt, answer)
|
||||
out = to_text(out, errors='surrogate_or_strict')
|
||||
|
||||
try:
|
||||
out = self._module.from_json(out)
|
||||
except ValueError:
|
||||
out = str(out).strip()
|
||||
|
||||
responses.append(out)
|
||||
|
||||
return responses
|
||||
|
||||
def send_config(self, commands):
|
||||
conn = self._get_connection()
|
||||
|
||||
multiline = False
|
||||
rc = 0
|
||||
for command in to_list(commands):
|
||||
if command == 'end':
|
||||
continue
|
||||
|
||||
if command.startswith('banner') or multiline:
|
||||
multiline = True
|
||||
elif command == 'EOF' and multiline:
|
||||
multiline = False
|
||||
|
||||
conn.get(command, None, None, multiline)
|
||||
return connection.run_commands(commands, check_rc)
|
||||
|
||||
def configure(self, commands):
|
||||
"""Sends configuration commands to the remote device
|
||||
@@ -239,32 +201,12 @@ class Cli:
|
||||
return result
|
||||
|
||||
conn = self._get_connection()
|
||||
session = 'ansible_%s' % int(time.time())
|
||||
result = {'session': session}
|
||||
|
||||
out = conn.get('configure session %s' % session)
|
||||
|
||||
if replace:
|
||||
out = conn.get('rollback clean-config')
|
||||
|
||||
try:
|
||||
self.send_config(commands)
|
||||
return conn.load_config(commands, commit, replace)
|
||||
except ConnectionError as exc:
|
||||
self.close_session(session)
|
||||
message = getattr(exc, 'err', exc)
|
||||
self._module.fail_json(msg="Error on executing commands %s" % commands, data=to_text(message, errors='surrogate_then_replace'))
|
||||
|
||||
out = conn.get('show session-config diffs')
|
||||
if out:
|
||||
result['diff'] = to_text(out, errors='surrogate_then_replace').strip()
|
||||
|
||||
if commit:
|
||||
conn.get('commit')
|
||||
else:
|
||||
self.close_session(session)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
class Eapi:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user