Skip to content

Instantly share code, notes, and snippets.

@marcoceppi
Created June 3, 2015 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcoceppi/002ce8122f49a15c0153 to your computer and use it in GitHub Desktop.
Save marcoceppi/002ce8122f49a15c0153 to your computer and use it in GitHub Desktop.
Find if environment is idle
#!/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)
juju status | ./am-i-idle.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment