From 7c520ec00cdfba4abb17327c909e8313874f4ca7 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Tue, 17 Nov 2020 12:32:16 -0500 Subject: [PATCH] Add short pretty health output --- client-cli/cli_lib/cluster.py | 15 +++++++++++++++ client-cli/pvc.py | 8 +++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/client-cli/cli_lib/cluster.py b/client-cli/cli_lib/cluster.py index 158e90db..9d8e9e05 100644 --- a/client-cli/cli_lib/cluster.py +++ b/client-cli/cli_lib/cluster.py @@ -104,6 +104,20 @@ def format_info(cluster_information, oformat): storage_health_colour = ansiprint.yellow() ainformation = [] + + if oformat == 'short': + ainformation.append('{}PVC cluster status:{}'.format(ansiprint.bold(), ansiprint.end())) + ainformation.append('{}Cluster health:{} {}{}{}'.format(ansiprint.purple(), ansiprint.end(), health_colour, cluster_information['health'], ansiprint.end())) + if cluster_information['health_msg']: + for line in cluster_information['health_msg']: + ainformation.append(' > {}'.format(line)) + ainformation.append('{}Storage health:{} {}{}{}'.format(ansiprint.purple(), ansiprint.end(), storage_health_colour, cluster_information['storage_health'], ansiprint.end())) + if cluster_information['storage_health_msg']: + for line in cluster_information['storage_health_msg']: + ainformation.append(' > {}'.format(line)) + + return '\n'.join(ainformation) + ainformation.append('{}PVC cluster status:{}'.format(ansiprint.bold(), ansiprint.end())) ainformation.append('') ainformation.append('{}Cluster health:{} {}{}{}'.format(ansiprint.purple(), ansiprint.end(), health_colour, cluster_information['health'], ansiprint.end())) @@ -114,6 +128,7 @@ def format_info(cluster_information, oformat): if cluster_information['storage_health_msg']: for line in cluster_information['storage_health_msg']: ainformation.append(' > {}'.format(line)) + ainformation.append('') ainformation.append('{}Primary node:{} {}'.format(ansiprint.purple(), ansiprint.end(), cluster_information['primary_node'])) ainformation.append('{}Cluster upstream IP:{} {}'.format(ansiprint.purple(), ansiprint.end(), cluster_information['upstream_ip'])) diff --git a/client-cli/pvc.py b/client-cli/pvc.py index 7c0afc77..a62e49b2 100755 --- a/client-cli/pvc.py +++ b/client-cli/pvc.py @@ -4057,13 +4057,19 @@ def maintenance_off(): @click.command(name='status', short_help='Show current cluster status.') @click.option( '-f', '--format', 'oformat', default='plain', show_default=True, - type=click.Choice(['plain', 'json', 'json-pretty']), + type=click.Choice(['plain', 'short', 'json', 'json-pretty']), help='Output format of cluster status information.' ) @cluster_req def status_cluster(oformat): """ Show basic information and health for the active PVC cluster. + + Output formats: + plain: Full text, full colour output for human-readability. + short: Health-only, full colour output for human-readability. + json: Compact JSON representation for machine parsing. + json-pretty: Pretty-printed JSON representation for machine parsing or human-readability. """ retcode, retdata = pvc_cluster.get_info(config)