blob: 11909b6fdd27b6d11cd791de1ebf65e9a9c4ff36 [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
Andy Bavier88e198e2017-05-08 14:59:18 -040010try:
11 juju_status_json = subprocess.check_output("juju status --format=json", shell=True)
12 juju_status = json.loads(juju_status_json)
13except:
14 print json.dumps({
15 "failed" : True,
16 "msg" : "'juju status' command failed"
17 })
18 sys.exit(1)
Zack Williams2eb97f92016-02-29 09:37:36 -070019
20juju_machines = {}
21for index, data in juju_status['machines'].iteritems():
22 data_underscore = dict_keys_dash_to_underscore(data)
23 juju_machines[data_underscore["dns_name"]] = data_underscore
Zack Williamsf1fb0942016-02-29 14:48:01 -070024 juju_machines[data_underscore["dns_name"]]["machine_id"] = index
Zack Williams2eb97f92016-02-29 09:37:36 -070025
Zack Williams2de6f5e2016-03-15 09:57:52 -070026juju_compute_nodes = {}
Zack Williams439ddb92016-03-16 16:06:23 -070027if 'nova-compute' in juju_status['services']:
28 for name, data in juju_status['services']['nova-compute']['units'].iteritems():
29 juju_compute_nodes[data['public-address']] = data
Zack Williams2de6f5e2016-03-15 09:57:52 -070030
Zack Williams2eb97f92016-02-29 09:37:36 -070031print json.dumps({
32 "changed": True,
33 "ansible_facts" : {
Zack Williams2de6f5e2016-03-15 09:57:52 -070034 "juju_environment": juju_status['environment'],
Zack Williams2eb97f92016-02-29 09:37:36 -070035 "juju_machines": juju_machines,
Zack Williamsf1fb0942016-02-29 14:48:01 -070036 "juju_services": juju_status['services'],
Zack Williams2de6f5e2016-03-15 09:57:52 -070037 "juju_compute_nodes": juju_compute_nodes,
Zack Williams2eb97f92016-02-29 09:37:36 -070038 },
39})
40