blob: 3a75b0795ac69b7730b250fc27e9c13762da5628 [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",
Andy Bavier093e6a82015-08-21 13:31:31 -040011 "neutron-gateway", "openstack-dashboard", "ceilometer", "nagios", "neutron-api"]
Andy Bavier8d51c6c2015-04-01 11:40:22 -040012
13services = {
14 "mysql" : "mysql",
15 "rabbitmq-server" : "rabbitmq-server",
16 "keystone" : "--config=%s keystone" % jujuconfig,
17 "glance" : "--config=%s glance" % jujuconfig,
Andy Bavier093e6a82015-08-21 13:31:31 -040018# "nova-cloud-controller" : "--config=%s cs:~andybavier/trusty/nova-cloud-controller" % jujuconfig,
Andy Bavier093e6a82015-08-21 13:31:31 -040019 "nova-cloud-controller" : "--config=%s nova-cloud-controller" % jujuconfig,
Andy Bavier5a4a2572015-08-27 13:16:50 -040020 "neutron-gateway" : "--config=%s cs:~andybavier/trusty/neutron-gateway" % jujuconfig,
21# "neutron-gateway" : "--config=%s neutron-gateway" % jujuconfig,
Andy Bavier093e6a82015-08-21 13:31:31 -040022 "neutron-api" : "--config=%s neutron-api" % jujuconfig,
23 "neutron-openvswitch" : "--config=%s neutron-openvswitch" % jujuconfig,
Andy Bavier8d51c6c2015-04-01 11:40:22 -040024 "openstack-dashboard" : "--config=%s openstack-dashboard" % jujuconfig,
25 "nagios" : "nagios",
26 "mongodb" : "mongodb", # deploy to ceilometer machine
27 "ceilometer" : "ceilometer",
28 "nrpe" : "nrpe",
29 "ntp" : "ntp",
30 "ceilometer-agent" : "ceilometer-agent"
31}
32
33# Figure out Juju ID of machine we should install on
34def get_machine(status, service):
35 if service == "mongodb":
36 service = "ceilometer"
37 for key, value in status['machines'].iteritems():
38 (hostname, aliaslist, ipaddrlist) = socket.gethostbyaddr(value['dns-name'])
39 if hostname == service:
40 return key
41 return None
42
43def deploy(status, service, cmd):
44 if service in status['services']:
45 return
46
47 print "Installing %s" % service
48 machine = get_machine(status, service)
49 if machine:
50 subprocess.check_call("juju deploy --to=%s %s" % (machine, cmd), shell=True)
51 else:
52 subprocess.check_call("juju deploy %s" % cmd, shell=True)
53
54def get_juju_status():
55 output = subprocess.check_output("juju status --format=json", shell=True)
56 status = json.loads(output)
57 return status
58
59def addservices():
60 status = get_juju_status()
61
62 for service, cmd in services.iteritems():
63 try:
64 deploy(status, service, cmd)
65 except:
66 pass
67
68def addmachines():
69 status = get_juju_status()
70
71 for machine in machines:
72 if get_machine(status, machine) == None:
73 ipaddr = socket.gethostbyname(machine)
74 subprocess.check_call("juju add-machine ssh:%s" % ipaddr, shell=True)
75
76def main():
77 addmachines()
78 addservices()
79
80if __name__ =='__main__':
81 main()