mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 03:41:25 -07:00
Fixes to httpapi for EAPI (#40675)
* Replace errant uses of str * Hook up become to eapi * Hook become up to nxapi, too
This commit is contained in:
parent
38c86b7eef
commit
0ad4b7b785
4 changed files with 36 additions and 17 deletions
|
@ -21,11 +21,13 @@ except ImportError:
|
|||
class HttpApi:
|
||||
def __init__(self, connection):
|
||||
self.connection = connection
|
||||
self._become = False
|
||||
|
||||
def send_request(self, data, **message_kwargs):
|
||||
if 'become' in message_kwargs:
|
||||
data = to_list(data)
|
||||
if self._become:
|
||||
display.vvvv('firing event: on_become')
|
||||
# TODO ??? self._terminal.on_become(passwd=auth_pass)
|
||||
data.insert(0, {"cmd": "enable", "input": self._become_pass})
|
||||
|
||||
output = message_kwargs.get('output', 'text')
|
||||
request = request_builder(data, output)
|
||||
|
@ -33,12 +35,23 @@ class HttpApi:
|
|||
|
||||
response = self.connection.send('/command-api', request, headers=headers, method='POST')
|
||||
response = json.loads(to_text(response.read()))
|
||||
return handle_response(response)
|
||||
results = handle_response(response)
|
||||
|
||||
if self._become:
|
||||
results = results[1:]
|
||||
if len(results) == 1:
|
||||
results = results[0]
|
||||
|
||||
return results
|
||||
|
||||
def get_prompt(self):
|
||||
# Hack to keep @enable_mode working
|
||||
return '#'
|
||||
|
||||
def set_become(self, play_context):
|
||||
self._become = play_context.become
|
||||
self._become_pass = getattr(play_context, 'become_pass') or ''
|
||||
|
||||
# Imported from module_utils
|
||||
def edit_config(self, config, commit=False, replace=False):
|
||||
"""Loads the configuration onto the remote devices
|
||||
|
@ -148,11 +161,9 @@ def handle_response(response):
|
|||
else:
|
||||
results.append(json.dumps(result))
|
||||
|
||||
if len(results) == 1:
|
||||
return results[0]
|
||||
return results
|
||||
|
||||
|
||||
def request_builder(commands, output, reqid=None):
|
||||
params = dict(version=1, cmds=to_list(commands), format=output)
|
||||
params = dict(version=1, cmds=commands, format=output)
|
||||
return json.dumps(dict(jsonrpc='2.0', id=reqid, method='runCmds', params=params))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue