blob: f8e18f40f5bceeb59946ed25edfccb0c49792c3d [file] [log] [blame]
Matteo Scandolo3896c472017-08-01 13:31:42 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
Zack Williams5e2a5852016-03-10 12:45:48 -070017#!/usr/bin/env python
Zack Williams2eb97f92016-02-29 09:37:36 -070018
19import json
20import subprocess
21
22def dict_keys_dash_to_underscore(dashed):
23 underscored = dict((k.replace('-','_'),v) for k,v in dashed.items())
24 return underscored
25
Andy Bavier88e198e2017-05-08 14:59:18 -040026try:
27 juju_status_json = subprocess.check_output("juju status --format=json", shell=True)
28 juju_status = json.loads(juju_status_json)
29except:
30 print json.dumps({
31 "failed" : True,
32 "msg" : "'juju status' command failed"
33 })
34 sys.exit(1)
Zack Williams2eb97f92016-02-29 09:37:36 -070035
36juju_machines = {}
37for index, data in juju_status['machines'].iteritems():
38 data_underscore = dict_keys_dash_to_underscore(data)
39 juju_machines[data_underscore["dns_name"]] = data_underscore
Zack Williamsf1fb0942016-02-29 14:48:01 -070040 juju_machines[data_underscore["dns_name"]]["machine_id"] = index
Zack Williams2eb97f92016-02-29 09:37:36 -070041
Zack Williams2de6f5e2016-03-15 09:57:52 -070042juju_compute_nodes = {}
Zack Williams439ddb92016-03-16 16:06:23 -070043if 'nova-compute' in juju_status['services']:
44 for name, data in juju_status['services']['nova-compute']['units'].iteritems():
45 juju_compute_nodes[data['public-address']] = data
Zack Williams2de6f5e2016-03-15 09:57:52 -070046
Zack Williams2eb97f92016-02-29 09:37:36 -070047print json.dumps({
48 "changed": True,
49 "ansible_facts" : {
Zack Williams2de6f5e2016-03-15 09:57:52 -070050 "juju_environment": juju_status['environment'],
Zack Williams2eb97f92016-02-29 09:37:36 -070051 "juju_machines": juju_machines,
Zack Williamsf1fb0942016-02-29 14:48:01 -070052 "juju_services": juju_status['services'],
Zack Williams2de6f5e2016-03-15 09:57:52 -070053 "juju_compute_nodes": juju_compute_nodes,
Zack Williams2eb97f92016-02-29 09:37:36 -070054 },
55})
56