mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
This reverts commit 4349b56643.
This commit is contained in:
@@ -65,10 +65,6 @@ def sort_list(val):
|
||||
class Entity(object):
|
||||
"""Transforms a dict to with an argument spec
|
||||
|
||||
This class has been deprecated as of Ansible 2.5 and will be
|
||||
removed from the code in future release.
|
||||
Please use the suboptions in module argument spec instead.
|
||||
|
||||
This class will take a dict and apply an Ansible argument spec to the
|
||||
values. The resulting dict will contain all of the keys in the param
|
||||
with appropriate values set.
|
||||
@@ -187,12 +183,7 @@ class Entity(object):
|
||||
|
||||
|
||||
class EntityCollection(Entity):
|
||||
"""Extends ```Entity``` to handle a list of dicts
|
||||
|
||||
This class has been deprecated as of Ansible 2.5 and will be
|
||||
removed from the code in future release.
|
||||
Please use the suboptions in module argument spec instead.
|
||||
"""
|
||||
"""Extends ```Entity``` to handle a list of dicts """
|
||||
|
||||
def __call__(self, iterable, strict=True):
|
||||
if iterable is None:
|
||||
@@ -207,21 +198,11 @@ class EntityCollection(Entity):
|
||||
# these two are for backwards compatibility and can be removed once all of the
|
||||
# modules that use them are updated
|
||||
class ComplexDict(Entity):
|
||||
"""
|
||||
This class has been deprecated as of Ansible 2.5 and will be
|
||||
removed from the code in future release.
|
||||
Please use the suboptions in module argument spec instead.
|
||||
"""
|
||||
def __init__(self, attrs, module, *args, **kwargs):
|
||||
super(ComplexDict, self).__init__(module, attrs, *args, **kwargs)
|
||||
|
||||
|
||||
class ComplexList(EntityCollection):
|
||||
"""
|
||||
This class has been deprecated as of Ansible 2.5 and will be
|
||||
removed from the code in future release.
|
||||
Please use the suboptions in module argument spec instead.
|
||||
"""
|
||||
def __init__(self, attrs, module, *args, **kwargs):
|
||||
super(ComplexList, self).__init__(module, attrs, *args, **kwargs)
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -27,9 +27,8 @@
|
||||
#
|
||||
from ansible.module_utils._text import to_text
|
||||
from ansible.module_utils.basic import env_fallback, return_values
|
||||
from ansible.module_utils.network.common.utils import to_list, ComplexList
|
||||
from ansible.module_utils.connection import exec_command
|
||||
from ansible.module_utils.network.common.utils import to_list
|
||||
from ansible.module_utils.six import string_types
|
||||
|
||||
_DEVICE_CONFIGS = {}
|
||||
|
||||
@@ -101,12 +100,20 @@ def get_config(module, flags=None):
|
||||
return cfg
|
||||
|
||||
|
||||
def to_commands(module, commands):
|
||||
spec = {
|
||||
'command': dict(key=True),
|
||||
'prompt': dict(),
|
||||
'answer': dict()
|
||||
}
|
||||
transform = ComplexList(spec, module)
|
||||
return transform(commands)
|
||||
|
||||
|
||||
def run_commands(module, commands, check_rc=True):
|
||||
responses = list()
|
||||
for cmd in to_list(commands):
|
||||
if isinstance(cmd, string_types):
|
||||
cmd = {'command': cmd}
|
||||
|
||||
commands = to_commands(module, to_list(commands))
|
||||
for cmd in commands:
|
||||
cmd = module.jsonify(cmd)
|
||||
rc, out, err = exec_command(module, cmd)
|
||||
if check_rc and rc != 0:
|
||||
|
||||
@@ -79,6 +79,12 @@ iosxr_argument_spec = {
|
||||
'provider': dict(type='dict', options=iosxr_provider_spec)
|
||||
}
|
||||
|
||||
command_spec = {
|
||||
'command': dict(),
|
||||
'prompt': dict(default=None),
|
||||
'answer': dict(default=None)
|
||||
}
|
||||
|
||||
iosxr_top_spec = {
|
||||
'host': dict(removed_in_version=2.9),
|
||||
'port': dict(removed_in_version=2.9, type='int'),
|
||||
|
||||
@@ -32,7 +32,7 @@ import collections
|
||||
|
||||
from ansible.module_utils._text import to_text
|
||||
from ansible.module_utils.basic import env_fallback, return_values
|
||||
from ansible.module_utils.network.common.utils import to_list
|
||||
from ansible.module_utils.network.common.utils import to_list, ComplexList
|
||||
from ansible.module_utils.connection import exec_command
|
||||
from ansible.module_utils.six import iteritems, string_types
|
||||
from ansible.module_utils.urls import fetch_url
|
||||
@@ -399,6 +399,28 @@ def is_nxapi(module):
|
||||
return 'nxapi' in (transport, provider_transport)
|
||||
|
||||
|
||||
def to_command(module, commands):
|
||||
if is_nxapi(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)
|
||||
|
||||
commands = transform(to_list(commands))
|
||||
|
||||
for item in commands:
|
||||
if is_json(item['command']):
|
||||
item['output'] = 'json'
|
||||
|
||||
return commands
|
||||
|
||||
|
||||
def get_config(module, flags=None):
|
||||
flags = [] if flags is None else flags
|
||||
|
||||
@@ -408,20 +430,7 @@ def get_config(module, flags=None):
|
||||
|
||||
def run_commands(module, commands, check_rc=True):
|
||||
conn = get_connection(module)
|
||||
|
||||
if is_nxapi(module):
|
||||
default_output = 'json'
|
||||
else:
|
||||
default_output = 'text'
|
||||
|
||||
for index, cmd in enumerate(to_list(commands)):
|
||||
if isinstance(cmd, string_types):
|
||||
commands[index] = cmd = {'command': cmd, 'output': default_output}
|
||||
|
||||
if is_json(cmd['command']):
|
||||
cmd['output'] = 'json'
|
||||
|
||||
return conn.run_commands(to_list(commands), check_rc)
|
||||
return conn.run_commands(to_command(module, commands), check_rc)
|
||||
|
||||
|
||||
def load_config(module, config, return_error=False, opts=None):
|
||||
|
||||
Reference in New Issue
Block a user