blob: ba19ffd573df39e4aad92252b64332e0ebf907f8 [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",
9 "neutron-gateway", "openstack-dashboard", "ceilometer", "nagios", "neutron-api"]
10
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()