Andy Bavier | 2ab9b00 | 2016-02-01 15:06:13 -0500 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | import subprocess |
| 4 | import json |
| 5 | import socket |
| 6 | |
| 7 | # Assumption: VMs have same hostname as service that runs inside |
| 8 | machines = ["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 |
| 13 | def 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 | |
| 22 | def get_juju_status(): |
| 23 | output = subprocess.check_output("juju status --format=json", shell=True) |
| 24 | status = json.loads(output) |
| 25 | return status |
| 26 | |
| 27 | def 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 | |
| 35 | def main(): |
| 36 | addmachines() |
| 37 | |
| 38 | if __name__ =='__main__': |
| 39 | main() |