summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDhivyap <dhivya.p@dell.com>2017-04-17 17:40:41 +0530
committerJohn R Barker <john@johnrbarker.com>2017-04-17 13:10:41 +0100
commit3d65d9189b85c1e67d65005fefb0256226575e7a (patch)
treeea16907148c203977891c56a6e85791e66a24c5f
parentb4a2869c4a38f8afed387ad103cb4b37e720b25d (diff)
downloadansible-modules-core-3d65d9189b85c1e67d65005fefb0256226575e7a.tar.gz
Backporting fixes#5534 to support 2.2 (#5909)
-rw-r--r--network/dellos10/dellos10_command.py28
-rw-r--r--network/dellos6/dellos6_command.py26
-rwxr-xr-xnetwork/dellos9/dellos9_command.py29
3 files changed, 65 insertions, 18 deletions
diff --git a/network/dellos10/dellos10_command.py b/network/dellos10/dellos10_command.py
index 5c8e5ea3..a20a2946 100644
--- a/network/dellos10/dellos10_command.py
+++ b/network/dellos10/dellos10_command.py
@@ -139,16 +139,33 @@ warnings:
from ansible.module_utils.basic import get_exception
from ansible.module_utils.netcli import CommandRunner, FailedConditionsError
from ansible.module_utils.network import NetworkModule, NetworkError
+from ansible.module_utils.six import string_types
import ansible.module_utils.dellos10
+VALID_KEYS = ['command', 'prompt', 'response']
+
+
def to_lines(stdout):
for item in stdout:
if isinstance(item, basestring):
item = str(item).split('\n')
yield item
+
+def parse_commands(module):
+ for cmd in module.params['commands']:
+ if isinstance(cmd, string_types):
+ cmd = dict(command=cmd, output=None)
+ elif 'command' not in cmd:
+ module.fail_json(msg='command keyword argument is required')
+ elif not set(cmd.keys()).issubset(VALID_KEYS):
+ module.fail_json(msg='unknown keyword specified')
+ yield cmd
+
+
def main():
spec = dict(
+ # { command: <str>, prompt: <str>, response: <str> }
commands=dict(type='list', required=True),
wait_for=dict(type='list'),
retries=dict(default=10, type='int'),
@@ -159,7 +176,7 @@ def main():
connect_on_load=False,
supports_check_mode=True)
- commands = module.params['commands']
+ commands = list(parse_commands(module))
conditionals = module.params['wait_for'] or list()
warnings = list()
@@ -167,15 +184,15 @@ def main():
runner = CommandRunner(module)
for cmd in commands:
- if module.check_mode and not cmd.startswith('show'):
+ if module.check_mode and not cmd['command'].startswith('show'):
warnings.append('only show commands are supported when using '
'check mode, not executing `%s`' % cmd)
else:
- if cmd.startswith('conf'):
+ if cmd['command'].startswith('conf'):
module.fail_json(msg='dellos10_command does not support running '
'config mode commands. Please use '
'dellos10_config instead')
- runner.add_command(cmd)
+ runner.add_command(**cmd)
for item in conditionals:
runner.add_conditional(item)
@@ -197,12 +214,11 @@ def main():
result['stdout'] = list()
for cmd in commands:
try:
- output = runner.get_command(cmd)
+ output = runner.get_command(cmd['command'])
except ValueError:
output = 'command not executed due to check_mode, see warnings'
result['stdout'].append(output)
-
result['warnings'] = warnings
result['stdout_lines'] = list(to_lines(result['stdout']))
diff --git a/network/dellos6/dellos6_command.py b/network/dellos6/dellos6_command.py
index a9d442f4..debd008d 100644
--- a/network/dellos6/dellos6_command.py
+++ b/network/dellos6/dellos6_command.py
@@ -138,8 +138,12 @@ warnings:
from ansible.module_utils.basic import get_exception
from ansible.module_utils.netcli import CommandRunner, FailedConditionsError
from ansible.module_utils.network import NetworkModule, NetworkError
+from ansible.module_utils.six import string_types
import ansible.module_utils.dellos6
+VALID_KEYS = ['command', 'prompt', 'response']
+
+
def to_lines(stdout):
for item in stdout:
if isinstance(item, basestring):
@@ -147,8 +151,20 @@ def to_lines(stdout):
yield item
+def parse_commands(module):
+ for cmd in module.params['commands']:
+ if isinstance(cmd, string_types):
+ cmd = dict(command=cmd, output=None)
+ elif 'command' not in cmd:
+ module.fail_json(msg='command keyword argument is required')
+ elif not set(cmd.keys()).issubset(VALID_KEYS):
+ module.fail_json(msg='unknown keyword specified')
+ yield cmd
+
+
def main():
spec = dict(
+ # { command: <str>, prompt: <str>, response: <str> }
commands=dict(type='list', required=True),
wait_for=dict(type='list'),
retries=dict(default=10, type='int'),
@@ -159,7 +175,7 @@ def main():
connect_on_load=False,
supports_check_mode=True)
- commands = module.params['commands']
+ commands = list(parse_commands(module))
conditionals = module.params['wait_for'] or list()
warnings = list()
@@ -167,15 +183,15 @@ def main():
runner = CommandRunner(module)
for cmd in commands:
- if module.check_mode and not cmd.startswith('show'):
+ if module.check_mode and not cmd['command'].startswith('show'):
warnings.append('only show commands are supported when using '
'check mode, not executing `%s`' % cmd)
else:
- if cmd.startswith('conf'):
+ if cmd['command'].startswith('conf'):
module.fail_json(msg='dellos6_command does not support running '
'config mode commands. Please use '
'dellos6_config instead')
- runner.add_command(cmd)
+ runner.add_command(**cmd)
for item in conditionals:
runner.add_conditional(item)
@@ -197,7 +213,7 @@ def main():
result['stdout'] = list()
for cmd in commands:
try:
- output = runner.get_command(cmd)
+ output = runner.get_command(cmd['command'])
except ValueError:
output = 'command not executed due to check_mode, see warnings'
result['stdout'].append(output)
diff --git a/network/dellos9/dellos9_command.py b/network/dellos9/dellos9_command.py
index cc610855..950bdf4b 100755
--- a/network/dellos9/dellos9_command.py
+++ b/network/dellos9/dellos9_command.py
@@ -73,8 +73,8 @@ notes:
- This module requires Dell OS9 version 9.10.0.1P13 or above.
- This module requires to increase the ssh connection rate limit.
- Use the following command I(ip ssh connection-rate-limit 60)
- to configure the same. This can be done via M(dnos_config) module
+ Use the following command I(ip ssh connection-rate-limit 60)
+ to configure the same. This can be done via M(dnos_config) module
as well.
"""
@@ -148,8 +148,11 @@ warnings:
from ansible.module_utils.basic import get_exception
from ansible.module_utils.netcli import CommandRunner, FailedConditionsError
from ansible.module_utils.network import NetworkModule, NetworkError
+from ansible.module_utils.six import string_types
import ansible.module_utils.dellos9
+VALID_KEYS = ['command', 'prompt', 'response']
+
def to_lines(stdout):
for item in stdout:
@@ -158,8 +161,20 @@ def to_lines(stdout):
yield item
+def parse_commands(module):
+ for cmd in module.params['commands']:
+ if isinstance(cmd, string_types):
+ cmd = dict(command=cmd, output=None)
+ elif 'command' not in cmd:
+ module.fail_json(msg='command keyword argument is required')
+ elif not set(cmd.keys()).issubset(VALID_KEYS):
+ module.fail_json(msg='unknown keyword specified')
+ yield cmd
+
+
def main():
spec = dict(
+ # { command: <str>, prompt: <str>, response: <str> }
commands=dict(type='list', required=True),
wait_for=dict(type='list'),
retries=dict(default=10, type='int'),
@@ -170,7 +185,7 @@ def main():
connect_on_load=False,
supports_check_mode=True)
- commands = module.params['commands']
+ commands = list(parse_commands(module))
conditionals = module.params['wait_for'] or list()
warnings = list()
@@ -178,15 +193,15 @@ def main():
runner = CommandRunner(module)
for cmd in commands:
- if module.check_mode and not cmd.startswith('show'):
+ if module.check_mode and not cmd['command'].startswith('show'):
warnings.append('only show commands are supported when using '
'check mode, not executing `%s`' % cmd)
else:
- if cmd.startswith('conf'):
+ if cmd['command'].startswith('conf'):
module.fail_json(msg='dellos9_command does not support running '
'config mode commands. Please use '
'dellos9_config instead')
- runner.add_command(cmd)
+ runner.add_command(**cmd)
for item in conditionals:
runner.add_conditional(item)
@@ -208,7 +223,7 @@ def main():
result['stdout'] = list()
for cmd in commands:
try:
- output = runner.get_command(cmd)
+ output = runner.get_command(cmd['command'])
except ValueError:
output = 'command not executed due to check_mode, see warnings'
result['stdout'].append(output)