blob: cc62b5008e042b9039296f67d54f00c8867e4801 [file] [log] [blame]
Andy Bavier8d51c6c2015-04-01 11:40:22 -04001#!/usr/bin/python
2
3import subprocess
4import json
5import time
6
7jujuconfig="/home/ubuntu/openstack.cfg"
8
9services = {
10 "nova-compute" : "--config=%s cs:~andybavier/trusty/nova-compute" % jujuconfig,
11}
12
13def get_free_machines(status):
14 for (service, svcinfo) in status['services'].iteritems():
15 if 'units' in svcinfo:
16 for (unit, unitinfo) in svcinfo['units'].iteritems():
17 if 'machine' in unitinfo:
18 machine = unitinfo['machine']
19 status['machines'][machine]['unit'] = unit
20
21 free = {}
22 for (machine, mchinfo) in status['machines'].iteritems():
23 if machine == "0":
24 continue
25
26 if 'unit' not in mchinfo:
27 # print "%s: %s" % (machine, mchinfo['dns-name'])
28 free[machine] = mchinfo
29
30 return free
31
32
33def deploy(status, service, cmd):
34 # Deploy nova-compute to all free machines
35 machines = get_free_machines(status)
36
37 for (machine, mchinfo) in machines.iteritems():
38 if service in status['services']:
39 print "Adding unit %s on %s" % (service, mchinfo['dns-name'])
40 subprocess.check_call("juju add-unit --to=%s %s" % (machine, service), shell=True)
41 else:
42 print "Deploying service %s on %s" % (service, mchinfo['dns-name'])
43 subprocess.check_call("juju deploy --to=%s %s" % (machine, cmd), shell=True)
44 status['services'][service] = "installed"
45 time.sleep(10)
46
47def get_juju_status():
48 output = subprocess.check_output("juju status --format=json", shell=True)
49 status = json.loads(output)
50 return status
51
52def addservices():
53 status = get_juju_status()
54
55 for service, cmd in services.iteritems():
56 try:
57 deploy(status, service, cmd)
58 except:
59 pass
60
61def main():
62 addservices()
63
64if __name__ =='__main__':
65 main()