minor function clean ups in eos_command

This commit cleans up a couple of functions and removes the json
import to use the json methods from AnsibleModule
This commit is contained in:
Peter Sprygada 2016-03-11 22:06:06 -05:00
parent 7461feb737
commit cf3287b312

View file

@ -62,7 +62,6 @@ options:
trying the command again. trying the command again.
required: false required: false
default: 1 default: 1
""" """
EXAMPLES = """ EXAMPLES = """
@ -114,11 +113,10 @@ failed_conditions:
import time import time
import shlex import shlex
import re import re
import json
INDEX_RE = re.compile(r'(\[\d+\])') INDEX_RE = re.compile(r'(\[\d+\])')
def to_lines(stdout): def iterlines(stdout):
for item in stdout: for item in stdout:
if isinstance(item, basestring): if isinstance(item, basestring):
item = str(item).split('\n') item = str(item).split('\n')
@ -155,7 +153,7 @@ def main():
for index, cmd in enumerate(commands): for index, cmd in enumerate(commands):
if cmd.endswith('json'): if cmd.endswith('json'):
response[index] = json.loads(response[index]) response[index] = module.from_json(response[index])
for item in list(queue): for item in list(queue):
if item(response): if item(response):
@ -170,7 +168,7 @@ def main():
failed_conditions = [item.raw for item in queue] failed_conditions = [item.raw for item in queue]
module.fail_json(msg='timeout waiting for value', failed_conditions=failed_conditions) module.fail_json(msg='timeout waiting for value', failed_conditions=failed_conditions)
result['stdout_lines'] = list(to_lines(result['stdout'])) result['stdout_lines'] = list(iterlines(result['stdout']))
return module.exit_json(**result) return module.exit_json(**result)