From 5ee01e497b3053b117ee9e06d70cc3d709b51e06 Mon Sep 17 00:00:00 2001 From: Fabrice Krebs Date: Mon, 14 Oct 2024 11:31:58 +0200 Subject: [PATCH 1/2] Fixed issue #315 and #316 to allows JSON output and uniform parameters --- calm/dsl/cli/runbook_commands.py | 15 ++++++++++++--- calm/dsl/cli/runbooks.py | 9 +++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/calm/dsl/cli/runbook_commands.py b/calm/dsl/cli/runbook_commands.py index f51dd6a0..b446ff80 100644 --- a/calm/dsl/cli/runbook_commands.py +++ b/calm/dsl/cli/runbook_commands.py @@ -44,7 +44,7 @@ ) @click.option("--limit", "-l", default=20, help="Number of results to return") @click.option( - "--offset", "-o", default=0, help="Offset results by the specified amount" + "--offset", "-s", default=0, help="Offset results by the specified amount" ) @click.option( "--quiet", "-q", is_flag=True, default=False, help="Show only runbook names." @@ -52,10 +52,19 @@ @click.option( "--all-items", "-a", is_flag=True, help="Get all items, including deleted ones" ) -def _get_runbook_list(name, filter_by, limit, offset, quiet, all_items): +@click.option( + "--out", + "-o", + "out", + type=click.Choice(["text", "json"]), + default="text", + help="output format", +) + +def _get_runbook_list(name, filter_by, limit, offset, quiet, all_items, out): """Get the runbooks, optionally filtered by a string""" - get_runbook_list(name, filter_by, limit, offset, quiet, all_items) + get_runbook_list(name, filter_by, limit, offset, quiet, all_items, out) @get.command("runbook_executions", feature_min_version="3.0.0", experimental=True) diff --git a/calm/dsl/cli/runbooks.py b/calm/dsl/cli/runbooks.py index 9595244d..282e1293 100644 --- a/calm/dsl/cli/runbooks.py +++ b/calm/dsl/cli/runbooks.py @@ -46,7 +46,7 @@ LOG = get_logging_handle(__name__) -def get_runbook_list(name, filter_by, limit, offset, quiet, all_items): +def get_runbook_list(name, filter_by, limit, offset, quiet, all_items, out): """Get the runbooks, optionally filtered by a string""" client = get_api_client() @@ -75,7 +75,12 @@ def get_runbook_list(name, filter_by, limit, offset, quiet, all_items): LOG.warning("Cannot fetch runbooks from {}".format(pc_ip)) return - json_rows = res.json()["entities"] + res = res.json() + if out == "json": + click.echo(json.dumps(res, indent=4, separators=(",", ": "))) + return + + json_rows = res["entities"] if not json_rows: click.echo(highlight_text("No runbook found !!!\n")) return From edff7335183632cd7603c7df7fe689b688679f99 Mon Sep 17 00:00:00 2001 From: Fabrice Krebs Date: Mon, 14 Oct 2024 15:07:18 +0200 Subject: [PATCH 2/2] Make black applied changed --- calm/dsl/cli/runbook_commands.py | 1 - 1 file changed, 1 deletion(-) diff --git a/calm/dsl/cli/runbook_commands.py b/calm/dsl/cli/runbook_commands.py index b446ff80..06f2b2de 100644 --- a/calm/dsl/cli/runbook_commands.py +++ b/calm/dsl/cli/runbook_commands.py @@ -60,7 +60,6 @@ default="text", help="output format", ) - def _get_runbook_list(name, filter_by, limit, offset, quiet, all_items, out): """Get the runbooks, optionally filtered by a string"""