Zack Williams | 5e2a585 | 2016-03-10 12:45:48 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
Zack Williams | 2eb97f9 | 2016-02-29 09:37:36 -0700 | [diff] [blame] | 2 | |
| 3 | import json |
| 4 | import subprocess |
| 5 | |
| 6 | def dict_keys_dash_to_underscore(dashed): |
| 7 | underscored = dict((k.replace('-','_'),v) for k,v in dashed.items()) |
| 8 | return underscored |
| 9 | |
| 10 | juju_status_json = subprocess.check_output("juju status --format=json", shell=True) |
| 11 | juju_status = json.loads(juju_status_json) |
| 12 | |
| 13 | juju_machines = {} |
| 14 | for 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 Williams | f1fb094 | 2016-02-29 14:48:01 -0700 | [diff] [blame] | 17 | juju_machines[data_underscore["dns_name"]]["machine_id"] = index |
Zack Williams | 2eb97f9 | 2016-02-29 09:37:36 -0700 | [diff] [blame] | 18 | |
Zack Williams | 2de6f5e | 2016-03-15 09:57:52 -0700 | [diff] [blame] | 19 | juju_compute_nodes = {} |
Zack Williams | 439ddb9 | 2016-03-16 16:06:23 -0700 | [diff] [blame] | 20 | if '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 Williams | 2de6f5e | 2016-03-15 09:57:52 -0700 | [diff] [blame] | 23 | |
Zack Williams | 2eb97f9 | 2016-02-29 09:37:36 -0700 | [diff] [blame] | 24 | print json.dumps({ |
| 25 | "changed": True, |
| 26 | "ansible_facts" : { |
Zack Williams | 2de6f5e | 2016-03-15 09:57:52 -0700 | [diff] [blame] | 27 | "juju_environment": juju_status['environment'], |
Zack Williams | 2eb97f9 | 2016-02-29 09:37:36 -0700 | [diff] [blame] | 28 | "juju_machines": juju_machines, |
Zack Williams | f1fb094 | 2016-02-29 14:48:01 -0700 | [diff] [blame] | 29 | "juju_services": juju_status['services'], |
Zack Williams | 2de6f5e | 2016-03-15 09:57:52 -0700 | [diff] [blame] | 30 | "juju_compute_nodes": juju_compute_nodes, |
Zack Williams | 2eb97f9 | 2016-02-29 09:37:36 -0700 | [diff] [blame] | 31 | }, |
| 32 | }) |
| 33 | |