blob: ca5cbfef9f0750cf15117add35443e04f8fe1436 [file] [log] [blame]
Andy Bavier8d51c6c2015-04-01 11:40:22 -04001#!/usr/bin/python
2
3import subprocess
4import json
5import socket
6
Andy Bavieredbc6fe2015-04-13 15:41:35 -04007jujuconfig="/usr/local/src/openstack.cfg"
Andy Bavier8d51c6c2015-04-01 11:40:22 -04008
9# Assumption: VMs have same hostname as service that runs inside
10machines = ["mysql", "rabbitmq-server", "keystone", "glance", "nova-cloud-controller",
11 "quantum-gateway", "openstack-dashboard", "ceilometer", "nagios"]
12
13services = {
14 "mysql" : "mysql",
15 "rabbitmq-server" : "rabbitmq-server",
16 "keystone" : "--config=%s keystone" % jujuconfig,
17 "glance" : "--config=%s glance" % jujuconfig,
18 "nova-cloud-controller" : "--config=%s cs:~andybavier/trusty/nova-cloud-controller" % jujuconfig,
19 "quantum-gateway" : "--config=%s cs:~andybavier/trusty/quantum-gateway" % jujuconfig,
20 "openstack-dashboard" : "--config=%s openstack-dashboard" % jujuconfig,
21 "nagios" : "nagios",
22 "mongodb" : "mongodb", # deploy to ceilometer machine
23 "ceilometer" : "ceilometer",
24 "nrpe" : "nrpe",
25 "ntp" : "ntp",
26 "ceilometer-agent" : "ceilometer-agent"
27}
28
29# Figure out Juju ID of machine we should install on
30def get_machine(status, service):
31 if service == "mongodb":
32 service = "ceilometer"
33 for key, value in status['machines'].iteritems():
34 (hostname, aliaslist, ipaddrlist) = socket.gethostbyaddr(value['dns-name'])
35 if hostname == service:
36 return key
37 return None
38
39def deploy(status, service, cmd):
40 if service in status['services']:
41 return
42
43 print "Installing %s" % service
44 machine = get_machine(status, service)
45 if machine:
46 subprocess.check_call("juju deploy --to=%s %s" % (machine, cmd), shell=True)
47 else:
48 subprocess.check_call("juju deploy %s" % cmd, shell=True)
49
50def get_juju_status():
51 output = subprocess.check_output("juju status --format=json", shell=True)
52 status = json.loads(output)
53 return status
54
55def addservices():
56 status = get_juju_status()
57
58 for service, cmd in services.iteritems():
59 try:
60 deploy(status, service, cmd)
61 except:
62 pass
63
64def addmachines():
65 status = get_juju_status()
66
67 for machine in machines:
68 if get_machine(status, machine) == None:
69 ipaddr = socket.gethostbyname(machine)
70 subprocess.check_call("juju add-machine ssh:%s" % ipaddr, shell=True)
71
72def main():
73 addmachines()
74 addservices()
75
76if __name__ =='__main__':
77 main()