Andy Bavier | 8d51c6c | 2015-04-01 11:40:22 -0400 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | import subprocess |
| 4 | import json |
| 5 | import socket |
| 6 | |
Andy Bavier | edbc6fe | 2015-04-13 15:41:35 -0400 | [diff] [blame] | 7 | jujuconfig="/usr/local/src/openstack.cfg" |
Andy Bavier | 8d51c6c | 2015-04-01 11:40:22 -0400 | [diff] [blame] | 8 | |
| 9 | # Assumption: VMs have same hostname as service that runs inside |
| 10 | machines = ["mysql", "rabbitmq-server", "keystone", "glance", "nova-cloud-controller", |
Andy Bavier | 093e6a8 | 2015-08-21 13:31:31 -0400 | [diff] [blame] | 11 | "neutron-gateway", "openstack-dashboard", "ceilometer", "nagios", "neutron-api"] |
Andy Bavier | 8d51c6c | 2015-04-01 11:40:22 -0400 | [diff] [blame] | 12 | |
| 13 | services = { |
| 14 | "mysql" : "mysql", |
| 15 | "rabbitmq-server" : "rabbitmq-server", |
| 16 | "keystone" : "--config=%s keystone" % jujuconfig, |
| 17 | "glance" : "--config=%s glance" % jujuconfig, |
Andy Bavier | 093e6a8 | 2015-08-21 13:31:31 -0400 | [diff] [blame] | 18 | # "nova-cloud-controller" : "--config=%s cs:~andybavier/trusty/nova-cloud-controller" % jujuconfig, |
Andy Bavier | 093e6a8 | 2015-08-21 13:31:31 -0400 | [diff] [blame] | 19 | "nova-cloud-controller" : "--config=%s nova-cloud-controller" % jujuconfig, |
Andy Bavier | 5a4a257 | 2015-08-27 13:16:50 -0400 | [diff] [blame] | 20 | "neutron-gateway" : "--config=%s cs:~andybavier/trusty/neutron-gateway" % jujuconfig, |
| 21 | # "neutron-gateway" : "--config=%s neutron-gateway" % jujuconfig, |
Andy Bavier | 093e6a8 | 2015-08-21 13:31:31 -0400 | [diff] [blame] | 22 | "neutron-api" : "--config=%s neutron-api" % jujuconfig, |
| 23 | "neutron-openvswitch" : "--config=%s neutron-openvswitch" % jujuconfig, |
Andy Bavier | 8d51c6c | 2015-04-01 11:40:22 -0400 | [diff] [blame] | 24 | "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 |
| 34 | def 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 | |
| 43 | def 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 | |
| 54 | def get_juju_status(): |
| 55 | output = subprocess.check_output("juju status --format=json", shell=True) |
| 56 | status = json.loads(output) |
| 57 | return status |
| 58 | |
| 59 | def 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 | |
| 68 | def 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 | |
| 76 | def main(): |
| 77 | addmachines() |
| 78 | addservices() |
| 79 | |
| 80 | if __name__ =='__main__': |
| 81 | main() |