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