Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue #315 and #316 to allows JSON output and uniform parameters #317

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions calm/dsl/cli/runbook_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,26 @@
)
@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."
)
@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)
Expand Down
9 changes: 7 additions & 2 deletions calm/dsl/cli/runbooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
Loading