From f2d2537e1cda0959f244682be5fb5d2070312bc9 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Wed, 15 Feb 2023 21:35:44 -0500 Subject: [PATCH] Add JSON output format for node info --- client-cli/pvc/pvc.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/client-cli/pvc/pvc.py b/client-cli/pvc/pvc.py index ec13fa9e..f17f5d50 100755 --- a/client-cli/pvc/pvc.py +++ b/client-cli/pvc/pvc.py @@ -697,15 +697,29 @@ def node_log(node, lines, follow): default=False, help="Display more detailed information.", ) +@click.option( + "-f", + "--format", + "oformat", + default="plain", + show_default=True, + type=click.Choice(["plain", "json", "json-pretty"]), + help="Output format of node status information.", +) @cluster_req -def node_info(node, long_output): +def node_info(node, long_output, oformat): """ Show information about node NODE. If unspecified, defaults to this host. """ retcode, retdata = pvc_node.node_info(config, node) if retcode: - retdata = pvc_node.format_info(retdata, long_output) + if oformat == "json": + retdata = json.dumps(retdata) + elif oformat == "json-pretty": + retdata = json.dumps(retdata, indent=4) + else: + retdata = pvc_node.format_info(retdata, long_output) cleanup(retcode, retdata)