mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 14:20:22 -07:00
This reverts commit 4349b56643
.
This commit is contained in:
parent
b6528ea19f
commit
ea18b9021a
15 changed files with 200 additions and 195 deletions
|
@ -33,8 +33,8 @@ import time
|
|||
from ansible.module_utils._text import to_text, to_native
|
||||
from ansible.module_utils.basic import env_fallback, return_values
|
||||
from ansible.module_utils.connection import exec_command
|
||||
from ansible.module_utils.network.common.utils import to_list
|
||||
from ansible.module_utils.six import iteritems, string_types
|
||||
from ansible.module_utils.network.common.utils import to_list, ComplexList
|
||||
from ansible.module_utils.six import iteritems
|
||||
from ansible.module_utils.urls import fetch_url
|
||||
|
||||
_DEVICE_CONNECTION = None
|
||||
|
@ -150,6 +150,7 @@ class Cli:
|
|||
"""Run list of commands on remote device and return results
|
||||
"""
|
||||
responses = list()
|
||||
|
||||
for cmd in to_list(commands):
|
||||
rc, out, err = self.exec_command(cmd)
|
||||
out = to_text(out, errors='surrogate_then_replace')
|
||||
|
@ -428,6 +429,22 @@ def is_eapi(module):
|
|||
return 'eapi' in (transport, provider_transport)
|
||||
|
||||
|
||||
def to_command(module, commands):
|
||||
if is_eapi(module):
|
||||
default_output = 'json'
|
||||
else:
|
||||
default_output = 'text'
|
||||
|
||||
transform = ComplexList(dict(
|
||||
command=dict(key=True),
|
||||
output=dict(default=default_output),
|
||||
prompt=dict(),
|
||||
answer=dict()
|
||||
), module)
|
||||
|
||||
return transform(to_list(commands))
|
||||
|
||||
|
||||
def get_config(module, flags=None):
|
||||
flags = None if flags is None else flags
|
||||
|
||||
|
@ -437,15 +454,7 @@ def get_config(module, flags=None):
|
|||
|
||||
def run_commands(module, commands):
|
||||
conn = get_connection(module)
|
||||
if is_eapi(module):
|
||||
default_output = 'json'
|
||||
else:
|
||||
default_output = 'text'
|
||||
|
||||
for index, cmd in enumerate(to_list(commands)):
|
||||
if isinstance(cmd, string_types):
|
||||
commands[index] = {'command': cmd, 'output': default_output}
|
||||
return conn.run_commands(to_list(commands))
|
||||
return conn.run_commands(to_command(module, commands))
|
||||
|
||||
|
||||
def load_config(module, config, commit=False, replace=False):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue