import click
from osmclient.cli_commands import common
+from osmclient.common import print_output
import logging
logger = logging.getLogger("osmclient")
"--filter",
help="restricts the list to the items matching the filter",
)
+@print_output.output_option
@click.pass_context
-def app_profile_list(ctx, filter):
+def app_profile_list(ctx, filter, output):
"""list all App Profiles"""
logger.debug("")
- common.generic_list(callback=ctx.obj.app_profile.list, filter=filter)
+ common.generic_list(callback=ctx.obj.app_profile.list, filter=filter, format=output)
@click.command(
short_help="shows the details of an App Profile",
)
@click.argument("name")
+@print_output.output_option
@click.pass_context
-def app_profile_show(ctx, name):
+def app_profile_show(ctx, name, output):
"""shows the details of an App Profile
NAME: name or ID of the App Profile
"""
logger.debug("")
- common.generic_show(callback=ctx.obj.app_profile.get, name=name)
+ common.generic_show(callback=ctx.obj.app_profile.get, name=name, format=output)
@click.command(name="app-profile-update", short_help="updates an App Profile")
import click
from osmclient.cli_commands import common
+from osmclient.common import print_output
import logging
import yaml
"--filter",
help="restricts the list to the items matching the filter",
)
+@print_output.output_option
@click.pass_context
-def cluster_list(ctx, filter):
+def cluster_list(ctx, filter, output):
"""list all K8s clusters"""
logger.debug("")
extras = {"Created": "created"}
- common.generic_list(callback=ctx.obj.cluster.list, filter=filter, extras=extras)
+ common.generic_list(
+ callback=ctx.obj.cluster.list, filter=filter, format=output, extras=extras
+ )
@click.command(
short_help="shows the details of a K8s cluster",
)
@click.argument("name")
+@print_output.output_option
@click.pass_context
-def cluster_show(ctx, name):
+def cluster_show(ctx, name, output):
"""shows the details of a K8s cluster
NAME: name or ID of the K8s cluster
"""
logger.debug("")
- common.generic_show(callback=ctx.obj.cluster.get, name=name)
+ common.generic_show(callback=ctx.obj.cluster.get, name=name, format=output)
@click.command(name="cluster-update", short_help="updates a K8s cluster")
#######################################################################################
import logging
import json
+from osmclient.cli_commands import utils
from osmclient.common import print_output
from osmclient.common.exceptions import ClientException
if format == "table" or format == "csv":
if resp:
for k, v in list(resp.items()):
- rows.append([k, json.dumps(v, indent=2)])
+ rows.append(
+ [
+ utils.wrap_text(k, 30),
+ utils.wrap_text(text=json.dumps(v, indent=2)),
+ ]
+ )
print_output.print_output(format, headers, rows, resp)
-def generic_list(callback, filter, format="table", extras={}):
+def generic_list(callback, filter, format="table", extras=None):
+ if not extras:
+ extras = {}
logger.debug("")
if filter:
filter = "&".join(filter)
import click
from osmclient.cli_commands import common
+from osmclient.common import print_output
import logging
logger = logging.getLogger("osmclient")
"--filter",
help="restricts the list to the items matching the filter",
)
+@print_output.output_option
@click.pass_context
-def infra_config_profile_list(ctx, filter):
+def infra_config_profile_list(ctx, filter, output):
"""list all Infra Config Profiles"""
logger.debug("")
- common.generic_list(callback=ctx.obj.infra_config_profile.list, filter=filter)
+ common.generic_list(
+ callback=ctx.obj.infra_config_profile.list, filter=filter, format=output
+ )
@click.command(
short_help="shows the details of an Infra Config Profile",
)
@click.argument("name")
+@print_output.output_option
@click.pass_context
-def infra_config_profile_show(ctx, name):
+def infra_config_profile_show(ctx, name, output):
"""shows the details of an Infra Config Profile
NAME: name or ID of the Infra Config Profile
"""
logger.debug("")
- common.generic_show(callback=ctx.obj.infra_config_profile.get, name=name)
+ common.generic_show(
+ callback=ctx.obj.infra_config_profile.get, name=name, format=output
+ )
@click.command(
import click
from osmclient.cli_commands import common
+from osmclient.common import print_output
import logging
logger = logging.getLogger("osmclient")
"--filter",
help="restricts the list to the items matching the filter",
)
+@print_output.output_option
@click.pass_context
-def infra_controller_profile_list(ctx, filter):
+def infra_controller_profile_list(ctx, filter, output):
"""list all Infra Controller Profiles"""
logger.debug("")
- common.generic_list(callback=ctx.obj.infra_controller_profile.list, filter=filter)
+ common.generic_list(
+ callback=ctx.obj.infra_controller_profile.list, filter=filter, format=output
+ )
@click.command(
)
@click.argument("name")
@click.pass_context
-def infra_controller_profile_show(ctx, name):
+@print_output.output_option
+def infra_controller_profile_show(ctx, name, output):
"""shows the details of an Infra Controller Profile
NAME: name or ID of the Infra Controller Profile
"""
logger.debug("")
- common.generic_show(callback=ctx.obj.infra_controller_profile.get, name=name)
+ common.generic_show(
+ callback=ctx.obj.infra_controller_profile.get, name=name, format=output
+ )
@click.command(
import click
from osmclient.cli_commands import common
from osmclient.common.exceptions import ClientException
+from osmclient.common import print_output
import logging
import yaml
"--filter",
help="restricts the list to the items matching the filter",
)
+@print_output.output_option
@click.pass_context
-def ksu_list(ctx, filter):
+def ksu_list(ctx, filter, output):
"""list all Kubernetes SW Units (KSU)"""
logger.debug("")
common.generic_list(callback=ctx.obj.ksu.list, filter=filter)
@click.command(name="ksu-show", short_help="shows the details of a KSU")
@click.argument("name")
+@print_output.output_option
@click.pass_context
-def ksu_show(ctx, name):
+def ksu_show(ctx, name, output):
"""shows the details of a KSU
NAME: name or ID of the KSU
import click
from osmclient.cli_commands import common
+from osmclient.common import print_output
import logging
logger = logging.getLogger("osmclient")
"--filter",
help="restricts the list to the items matching the filter",
)
+@print_output.output_option
@click.pass_context
-def oka_list(ctx, filter):
+def oka_list(ctx, filter, output):
"""list all OSM Kubernetes Application (OKA)"""
logger.debug("")
common.generic_list(callback=ctx.obj.oka.list, filter=filter)
short_help="shows the details of an OKA",
)
@click.argument("name")
+@print_output.output_option
@click.pass_context
-def oka_show(ctx, name):
+def oka_show(ctx, name, output):
"""shows the details of an OKA
NAME: name or ID of the OKA
import click
from osmclient.cli_commands import common
+from osmclient.common import print_output
import logging
logger = logging.getLogger("osmclient")
"--filter",
help="restricts the list to the items matching the filter",
)
+@print_output.output_option
@click.pass_context
-def resource_profile_list(ctx, filter):
+def resource_profile_list(ctx, filter, output):
"""list all Resource Profiles"""
logger.debug("")
- common.generic_list(callback=ctx.obj.resource_profile.list, filter=filter)
+ common.generic_list(
+ callback=ctx.obj.resource_profile.list, filter=filter, format=output
+ )
@click.command(
short_help="shows the details of an Resource Profile",
)
@click.argument("name")
+@print_output.output_option
@click.pass_context
-def resource_profile_show(ctx, name):
+def resource_profile_show(ctx, name, output):
"""shows the details of an Resource Profile
NAME: name or ID of the Resource Profile
"""
logger.debug("")
- common.generic_show(callback=ctx.obj.resource_profile.get, name=name)
+ common.generic_show(callback=ctx.obj.resource_profile.get, name=name, format=output)
@click.command(name="resource-profile-update", short_help="updates an Resource Profile")
import textwrap
import logging
+import shutil
import yaml
from osmclient.common.exceptions import ClientException
logger = logging.getLogger("osmclient")
-def wrap_text(text, width):
+def wrap_text(text, width=0):
+ if not width:
+ terminal_width = shutil.get_terminal_size().columns
+ width = max(terminal_width - 34, 40)
wrapper = textwrap.TextWrapper(width=width)
lines = text.splitlines()
return "\n".join(map(wrapper.fill, lines))
default="table",
is_eager=True,
callback=evaluate_output_format,
- help="output format (default: table)",
+ help="output format (table, json, yaml, csv, jsonpath=...) (default: table)",
)
)
-def print_output(format="table", headers=["field", "value"], rows=[], data=None):
+def print_output(format="table", headers=["field", "value"], rows=None, data=None):
"""
Prints content in specified format.
:param format: output format (table, yaml, json, csv, jsonpath=...). Default:
"""
logger.debug("")
+ if not rows:
+ rows = []
if format == "table":
table = PrettyTable(headers)
table.align = "l"