Created
June 6, 2014 18:37
-
-
Save kapilt/b017700f4cacd0b61cf4 to your computer and use it in GitHub Desktop.
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
""" | |
Allow for introspection of topolologies in flights | |
""" | |
from jujuctl.db import get_db | |
from jujuctl.env import get_env | |
def list_topologies(options): | |
db = get_db() | |
topologies = {} | |
for e in db.executions.find(): | |
t = topologies.setdefault(e['topology_id'], {}) | |
exe = { | |
'charm_url': e['charm_url'], | |
'lifecycle': e['lifecycle'], | |
'state': e['state']} | |
if 'server_group_id' in e: | |
exe['group'] = e['server_group_id'] | |
t.setdefault('events', []).append(exe) | |
env = get_env() | |
try: | |
status = env.get_stat() | |
finally: | |
env.close() | |
machine_unit_map = {} | |
for s, sdata in status['services'].items(): | |
for u, udata in sdata.get('units', {}).items(): | |
machine_unit_map['%s-%s' % ( | |
udata['machine'], s)] = udata.get( | |
'agent-state', 'pending') | |
for ec in db.execution_contexts.find(): | |
t = topologies.setdefault(ec['topology_id'], {}) | |
services = t.setdefault('services', {}) | |
svc_machines = services.setdefault(ec['_id'], {}) | |
for k, v in ec.get('env_machines', {}).items(): | |
d = {} | |
d['instance-id'] = k | |
d['agent-state'] = status['machines'].get(v, {}).get( | |
'agent-state') | |
d['unit-state'] = machine_unit_map.get('%s-%s' % ( | |
v, ec['_id'])) | |
svc_machines[v] = d | |
return topologies |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment