Better handle key values

This commit is contained in:
Joshua Boniface 2020-01-06 11:56:34 -05:00
parent 5edcd45ad6
commit 9ea86cc570
1 changed files with 3 additions and 7 deletions

View File

@ -114,9 +114,7 @@ def format_info(cluster_information, oformat):
ainformation.append('{}Total volumes:{} {}'.format(ansiprint.purple(), ansiprint.end(), cluster_information['volumes'])) ainformation.append('{}Total volumes:{} {}'.format(ansiprint.purple(), ansiprint.end(), cluster_information['volumes']))
ainformation.append('{}Total snapshots:{} {}'.format(ansiprint.purple(), ansiprint.end(), cluster_information['snapshots'])) ainformation.append('{}Total snapshots:{} {}'.format(ansiprint.purple(), ansiprint.end(), cluster_information['snapshots']))
nodes_string = '' nodes_string = '{}Nodes:{} {}/{} {}ready,run{}'.format(ansiprint.purple(), ansiprint.end(), cluster_information['nodes'].get('run,ready', 0), cluster_information['nodes'].get('total', 0), ansiprint.green(), ansiprint.end())
if cluster_information['nodes'].get('run,ready', None):
nodes_string += '{}Nodes:{} {}/{} {}ready,run{}'.format(ansiprint.purple(), ansiprint.end(), cluster_information['nodes']['run,ready'], cluster_information['nodes']['total'], ansiprint.green(), ansiprint.end())
for state, count in cluster_information['nodes'].items(): for state, count in cluster_information['nodes'].items():
if state == 'total' or state == 'run,ready': if state == 'total' or state == 'run,ready':
continue continue
@ -126,9 +124,7 @@ def format_info(cluster_information, oformat):
ainformation.append('') ainformation.append('')
ainformation.append(nodes_string) ainformation.append(nodes_string)
vms_string = '' vms_string = '{}VMs:{} {}/{} {}start{}'.format(ansiprint.purple(), ansiprint.end(), cluster_information['vms'].get('start', 0), cluster_information['vms'].get('total', 0), ansiprint.green(), ansiprint.end())
if cluster_information['vms'].get('start', None):
vms_string += '{}VMs:{} {}/{} {}start{}'.format(ansiprint.purple(), ansiprint.end(), cluster_information['vms']['start'], cluster_information['vms']['total'], ansiprint.green(), ansiprint.end())
for state, count in cluster_information['vms'].items(): for state, count in cluster_information['vms'].items():
if state == 'total' or state == 'start': if state == 'total' or state == 'start':
continue continue
@ -144,7 +140,7 @@ def format_info(cluster_information, oformat):
ainformation.append(vms_string) ainformation.append(vms_string)
if cluster_information['osds']['total'] > 0: if cluster_information['osds']['total'] > 0:
osds_string = '{}Ceph OSDs:{} {}/{} {}up,in{}'.format(ansiprint.purple(), ansiprint.end(), cluster_information['osds']['up,in'], cluster_information['osds']['total'], ansiprint.green(), ansiprint.end()) osds_string = '{}Ceph OSDs:{} {}/{} {}up,in{}'.format(ansiprint.purple(), ansiprint.end(), cluster_information['osds'].get('up,in', 0), cluster_information['osds'].get('total', 0), ansiprint.green(), ansiprint.end())
for state, count in cluster_information['osds'].items(): for state, count in cluster_information['osds'].items():
if state == 'total' or state == 'up,in': if state == 'total' or state == 'up,in':
continue continue