blob: 4ae84dbdd55ee80da09ead9228fe98956569f352 [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
19
20def dict_keys_dash_to_underscore(dashed):
21 underscored = dict((k.replace('-','_'),v) for k,v in dashed.items())
22 return underscored
23
Andy Bavier88e198e2017-05-08 14:59:18 -040024try:
25 juju_status_json = subprocess.check_output("juju status --format=json", shell=True)
26 juju_status = json.loads(juju_status_json)
27except:
28 print json.dumps({
29 "failed" : True,
30 "msg" : "'juju status' command failed"
31 })
32 sys.exit(1)
Zack Williams2eb97f92016-02-29 09:37:36 -070033
34juju_machines = {}
35for index, data in juju_status['machines'].iteritems():
36 data_underscore = dict_keys_dash_to_underscore(data)
37 juju_machines[data_underscore["dns_name"]] = data_underscore
Zack Williamsf1fb0942016-02-29 14:48:01 -070038 juju_machines[data_underscore["dns_name"]]["machine_id"] = index
Zack Williams2eb97f92016-02-29 09:37:36 -070039
Zack Williams2de6f5e2016-03-15 09:57:52 -070040juju_compute_nodes = {}
Zack Williams439ddb92016-03-16 16:06:23 -070041if 'nova-compute' in juju_status['services']:
42 for name, data in juju_status['services']['nova-compute']['units'].iteritems():
43 juju_compute_nodes[data['public-address']] = data
Zack Williams2de6f5e2016-03-15 09:57:52 -070044
Zack Williams2eb97f92016-02-29 09:37:36 -070045print json.dumps({
46 "changed": True,
47 "ansible_facts" : {
Zack Williams2de6f5e2016-03-15 09:57:52 -070048 "juju_environment": juju_status['environment'],
Zack Williams2eb97f92016-02-29 09:37:36 -070049 "juju_machines": juju_machines,
Zack Williamsf1fb0942016-02-29 14:48:01 -070050 "juju_services": juju_status['services'],
Zack Williams2de6f5e2016-03-15 09:57:52 -070051 "juju_compute_nodes": juju_compute_nodes,
Zack Williams2eb97f92016-02-29 09:37:36 -070052 },
53})
54