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", |
| 11 | "quantum-gateway", "openstack-dashboard", "ceilometer", "nagios"] |
| 12 | |
| 13 | services = { |
| 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 |
| 30 | def 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 | |
| 39 | def 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 | |
| 50 | def get_juju_status(): |
| 51 | output = subprocess.check_output("juju status --format=json", shell=True) |
| 52 | status = json.loads(output) |
| 53 | return status |
| 54 | |
| 55 | def 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 | |
| 64 | def 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 | |
| 72 | def main(): |
| 73 | addmachines() |
| 74 | addservices() |
| 75 | |
| 76 | if __name__ =='__main__': |
| 77 | main() |