Created
December 29, 2016 19:44
-
-
Save freyes/96daa52f5a6cbebb24c52f0ad04fa116 to your computer and use it in GitHub Desktop.
compact juju status for just the 'units' section
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python3 | |
| import json | |
| import subprocess | |
| from prettytable import PrettyTable, PLAIN_COLUMNS | |
| table = PrettyTable() | |
| table.field_names = ['unit', 'workload', 'agent', 'message'] | |
| table.set_style(PLAIN_COLUMNS) | |
| table.align['unit'] = table.align['message'] = 'l' | |
| st = subprocess.check_output(['juju', 'status', '--format', 'json'], | |
| universal_newlines=True) | |
| st = json.loads(st) | |
| for app_name, app in st['applications'].items(): | |
| if 'units' not in app: | |
| continue | |
| for unit_id, unit in app['units'].items(): | |
| table.add_row(["%s%s" % (unit_id, '*' if unit.get('leader') else ''), | |
| unit['workload-status']['current'], | |
| unit['juju-status']['current'], | |
| unit['workload-status'].get('message', '')]) | |
| if 'subordinates' not in unit: | |
| continue | |
| for sub_id, subor in unit['subordinates'].items(): | |
| table.add_row([" %s%s" % (sub_id, | |
| '*' if subor.get('leader') else ''), | |
| subor['workload-status']['current'], | |
| subor['juju-status']['current'], | |
| subor['workload-status'].get('message', '')]) | |
| print(table) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment