Created
June 3, 2015 19:03
-
-
Save marcoceppi/002ce8122f49a15c0153 to your computer and use it in GitHub Desktop.
Find if environment is idle
This file contains 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/env python | |
import sys | |
import yaml | |
status = yaml.load(sys.stdin) | |
j = {'idle': [], 'busy': []} | |
def is_agent_idle(data): | |
if 'agent-status' not in data: | |
raise Exception('This isnt a juju I know') | |
return data['agent-status']['current'] == 'idle' | |
def parse_units(units): | |
for unit, unit_data in units.iteritems(): | |
if not is_agent_idle(unit_data): | |
j['busy'].append(unit) | |
else: | |
j['idle'].append(unit) | |
if 'subordinates' in unit_data: | |
parse_units(unit_data['subordinates']) | |
for service, service_data in status['services'].iteritems(): | |
if 'units' in service_data: | |
parse_units(service_data['units']) | |
if j['busy']: | |
print '%s are busy' % ', '.join(j['busy']) | |
sys.exit(1) |
This file contains 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
juju status | ./am-i-idle.py |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment