update junos_command module return values
This minor update fixes the return values from the junos_command module to be consistent with other network modules
This commit is contained in:
parent
b7114cc783
commit
af40116e23
1 changed files with 11 additions and 7 deletions
|
@ -205,6 +205,12 @@ def parse_response(module, responses):
|
||||||
result['stdout_lines'].append(resp.split('\n'))
|
result['stdout_lines'].append(resp.split('\n'))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def to_lines(stdout):
|
||||||
|
for item in stdout:
|
||||||
|
if isinstance(item, basestring):
|
||||||
|
item = str(item).split('\n')
|
||||||
|
yield item
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
spec = dict(
|
spec = dict(
|
||||||
commands=dict(type='list'),
|
commands=dict(type='list'),
|
||||||
|
@ -229,23 +235,21 @@ def main():
|
||||||
except AttributeError, exc:
|
except AttributeError, exc:
|
||||||
module.fail_json(msg=exc.message)
|
module.fail_json(msg=exc.message)
|
||||||
|
|
||||||
result = dict(changed=False, stdout=list(), stdout_lines=list())
|
result = dict(changed=False)
|
||||||
|
|
||||||
while retries > 0:
|
while retries > 0:
|
||||||
try:
|
try:
|
||||||
response = module.execute(commands)
|
response = module.execute(commands)
|
||||||
|
result['stdout'] = response
|
||||||
except ShellError:
|
except ShellError:
|
||||||
module.fail_json(msg='failed to run commands')
|
module.fail_json(msg='failed to run commands')
|
||||||
|
|
||||||
values = list()
|
|
||||||
for index, cmd in enumerate(commands):
|
for index, cmd in enumerate(commands):
|
||||||
if cmd.endswith('json'):
|
if cmd.endswith('json'):
|
||||||
values.append(module.from_json(response[index]))
|
response[index] = json.loads(response[index])
|
||||||
else:
|
|
||||||
values.append(response[index])
|
|
||||||
|
|
||||||
for item in list(queue):
|
for item in list(queue):
|
||||||
if item(values):
|
if item(response):
|
||||||
queue.remove(item)
|
queue.remove(item)
|
||||||
|
|
||||||
if not queue:
|
if not queue:
|
||||||
|
@ -257,7 +261,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.update(parse_response(module, response))
|
result['stdout_lines'] = list(to_lines(result['stdout']))
|
||||||
return module.exit_json(**result)
|
return module.exit_json(**result)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue