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