Add short pretty health output

This commit is contained in:
Joshua Boniface 2020-11-17 12:32:16 -05:00
parent 9a36fedcab
commit 7c520ec00c
2 changed files with 22 additions and 1 deletions

View File

@ -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']))

View File

@ -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)