Last active
August 9, 2017 20:20
-
-
Save freyes/1dc611a232922e94d22eaa00c503db90 to your computer and use it in GitHub Desktop.
juju-st
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 | |
| # Usage: | |
| # $ juju status --format yaml | ./juju-st | |
| import yaml | |
| import select | |
| import subprocess | |
| import sys | |
| from pprint import pprint | |
| 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' | |
| if select.select([sys.stdin,],[],[],0.0)[0]: | |
| st = sys.stdin.read() | |
| else: | |
| st = subprocess.check_output(['juju', 'status', '--format', 'yaml', '--color'], | |
| universal_newlines=True) | |
| st = yaml.safe_load(st) | |
| for app_name, app in st['applications'].items(): | |
| if 'units' not in app: | |
| continue | |
| for unit_id, unit in sorted(app['units'].items(), key=lambda a: a[0]): | |
| 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 sorted(unit['subordinates'].items(), key=lambda a: a[0]): | |
| 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