blob: 3ba02c8d44d83cfb52aaa9051b6585b2eb6ecf51 [file] [log] [blame]
Zack Williams5e2a5852016-03-10 12:45:48 -07001#!/usr/bin/env python
Zack Williams2eb97f92016-02-29 09:37:36 -07002
3import json
4import subprocess
5
6def dict_keys_dash_to_underscore(dashed):
7 underscored = dict((k.replace('-','_'),v) for k,v in dashed.items())
8 return underscored
9
10juju_status_json = subprocess.check_output("juju status --format=json", shell=True)
11juju_status = json.loads(juju_status_json)
12
13juju_machines = {}
14for index, data in juju_status['machines'].iteritems():
15 data_underscore = dict_keys_dash_to_underscore(data)
16 juju_machines[data_underscore["dns_name"]] = data_underscore
Zack Williamsf1fb0942016-02-29 14:48:01 -070017 juju_machines[data_underscore["dns_name"]]["machine_id"] = index
Zack Williams2eb97f92016-02-29 09:37:36 -070018
Zack Williams2de6f5e2016-03-15 09:57:52 -070019juju_compute_nodes = {}
Zack Williams439ddb92016-03-16 16:06:23 -070020if 'nova-compute' in juju_status['services']:
21 for name, data in juju_status['services']['nova-compute']['units'].iteritems():
22 juju_compute_nodes[data['public-address']] = data
Zack Williams2de6f5e2016-03-15 09:57:52 -070023
Zack Williams2eb97f92016-02-29 09:37:36 -070024print json.dumps({
25 "changed": True,
26 "ansible_facts" : {
Zack Williams2de6f5e2016-03-15 09:57:52 -070027 "juju_environment": juju_status['environment'],
Zack Williams2eb97f92016-02-29 09:37:36 -070028 "juju_machines": juju_machines,
Zack Williamsf1fb0942016-02-29 14:48:01 -070029 "juju_services": juju_status['services'],
Zack Williams2de6f5e2016-03-15 09:57:52 -070030 "juju_compute_nodes": juju_compute_nodes,
Zack Williams2eb97f92016-02-29 09:37:36 -070031 },
32})
33