blob: 418aab2bcd760dcb6e401bfe4c3fa6a2c40bd13e [file] [log] [blame]
Andy Bavier2ab9b002016-02-01 15:06:13 -05001#!/usr/bin/python
2
3import subprocess
4import json
5import socket
6
7# Assumption: VMs have same hostname as service that runs inside
8machines = ["mysql", "rabbitmq-server", "keystone", "glance", "nova-cloud-controller",
Andy Bavier2c108de2016-02-18 16:55:00 -05009 "openstack-dashboard", "ceilometer", "nagios", "neutron-api"]
Andy Bavier2ab9b002016-02-01 15:06:13 -050010
11
12# Figure out Juju ID of machine we should install on
13def get_machine(status, service):
14 if service == "mongodb":
15 service = "ceilometer"
16 for key, value in status['machines'].iteritems():
17 (hostname, aliaslist, ipaddrlist) = socket.gethostbyaddr(value['dns-name'])
18 if hostname == service:
19 return key
20 return None
21
22def get_juju_status():
23 output = subprocess.check_output("juju status --format=json", shell=True)
24 status = json.loads(output)
25 return status
26
27def addmachines():
28 status = get_juju_status()
29
30 for machine in machines:
31 if get_machine(status, machine) == None:
32 ipaddr = socket.gethostbyname(machine)
33 subprocess.check_call("juju add-machine ssh:%s" % ipaddr, shell=True)
34
35def main():
36 addmachines()
37
38if __name__ =='__main__':
39 main()