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
pull/26461/merge
Ganesh Nalawade 7 years ago committed by Chris Alfonso
parent 58ade65ea6
commit 8c7a6cb8ac

@ -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__':

Loading…
Cancel
Save