From 397428d0bd7ba5183fb02c69e5b0ebc75387093f Mon Sep 17 00:00:00 2001 From: Balaji Date: Fri, 5 Jun 2020 09:43:11 -0700 Subject: [PATCH] fixes #71, json output for marketplace blueprints --- calm/dsl/cli/mpis.py | 12 ++++++++++-- calm/dsl/cli/mpis_commands.py | 24 ++++++++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/calm/dsl/cli/mpis.py b/calm/dsl/cli/mpis.py index aa287b68..799aca64 100644 --- a/calm/dsl/cli/mpis.py +++ b/calm/dsl/cli/mpis.py @@ -1,6 +1,7 @@ import uuid import click import sys +import json from prettytable import PrettyTable from calm.dsl.api import get_api_client, get_resource_api @@ -346,18 +347,19 @@ def get_mpi_by_name_n_version(name, version, app_states=[], app_source=None): return res -def describe_marketplace_item(name, version=None, app_source=None): +def describe_marketplace_item(name, out, version=None, app_source=None): """describes the marketplace blueprint related to marketplace item""" describe_marketplace_bp( name=name, + out=out, version=version, app_source=app_source, app_state=MARKETPLACE_BLUEPRINT.STATES.PUBLISHED, ) -def describe_marketplace_bp(name, version=None, app_source=None, app_state=None): +def describe_marketplace_bp(name, out, version=None, app_source=None, app_state=None): """describes the marketplace blueprint""" app_states = [app_state] if app_state else [] @@ -373,6 +375,12 @@ def describe_marketplace_bp(name, version=None, app_source=None, app_state=None) name=name, version=version, app_states=app_states, app_source=app_source ) + if out == "json": + blueprint = bp["status"]["resources"]["app_blueprint_template"] + blueprint.pop("status", None) + click.echo(json.dumps(blueprint, indent=4, separators=(",", ": "))) + return + click.echo("\n----MarketPlace Blueprint Summary----\n") click.echo( "Name: " diff --git a/calm/dsl/cli/mpis_commands.py b/calm/dsl/cli/mpis_commands.py index 76025dbc..e2b187ea 100644 --- a/calm/dsl/cli/mpis_commands.py +++ b/calm/dsl/cli/mpis_commands.py @@ -107,6 +107,14 @@ def _get_marketplace_bps(name, quiet, app_family, app_states): @describe.command("marketplace_item") @click.argument("name") +@click.option( + "--out", + "-o", + "out", + type=click.Choice(["text", "json"]), + default="text", + help="output format", +) @click.option("--version", "-v", default=None, help="Version of marketplace item") @click.option( "--source", @@ -115,14 +123,22 @@ def _get_marketplace_bps(name, quiet, app_family, app_states): type=click.Choice(APP_SOURCES), help="App Source for marketplace item", ) -def _describe_marketplace_item(name, version, source): +def _describe_marketplace_item(name, out, version, source): """Describe a market place item""" - describe_marketplace_item(name=name, version=version, app_source=source) + describe_marketplace_item(name=name, out=out, version=version, app_source=source) @describe.command("marketplace_bp") @click.argument("name") +@click.option( + "--out", + "-o", + "out", + type=click.Choice(["text", "json"]), + default="text", + help="output format.", +) @click.option("--version", "-v", default=None, help="Version of marketplace blueprint") @click.option( "--source", @@ -138,11 +154,11 @@ def _describe_marketplace_item(name, version, source): type=click.Choice(APP_STATES), help="State of marketplace blueprint", ) -def _describe_marketplace_bp(name, version, source, app_state): +def _describe_marketplace_bp(name, out, version, source, app_state): """Describe a market place blueprint""" describe_marketplace_bp( - name=name, version=version, app_source=source, app_state=app_state + name=name, out=out, version=version, app_source=source, app_state=app_state )