Add transformed json output in junos_command (#26382)

* Add transformed json output in junos_command

Fixes #26363
If the display is in `xml` format for command responses
add th transformed `json` output in the result.

* Fix CI issue
This commit is contained in:
Ganesh Nalawade 2017-07-10 22:05:28 +05:30 committed by Chris Alfonso
parent 58ade65ea6
commit 8c7a6cb8ac

View file

@ -157,6 +157,11 @@ stdout_lines:
returned: always apart from low level errors (such as action plugin)
type: list
sample: [['...', '...'], ['...'], ['...']]
output:
description: The set of transformed xml to json format from the commands responses
returned: If the I(display) is in C(xml) format.
type: list
sample: ['...', '...']
failed_conditions:
description: The list of conditionals that have failed
returned: failed
@ -348,7 +353,7 @@ def main():
responses = rpc(module, items)
transformed = list()
output = list()
for item, resp in zip(items, responses):
if item['xattrs']['format'] == 'xml':
if not HAS_JXMLEASE:
@ -356,7 +361,9 @@ def main():
'It can be installed using `pip install jxmlease`')
try:
transformed.append(jxmlease.parse(resp))
json_resp = jxmlease.parse(resp)
transformed.append(json_resp)
output.append(json_resp)
except:
raise ValueError(resp)
else:
@ -390,6 +397,9 @@ def main():
'stdout_lines': to_lines(responses)
}
if output:
result['output'] = output
module.exit_json(**result)
if __name__ == '__main__':