|
| 1 | +#!/opt/deis/controller/venv/bin/python |
| 2 | +import os |
| 3 | +import sys |
| 4 | +import json |
| 5 | + |
| 6 | +if __name__ == '__main__': |
| 7 | + # prepare pythonpath and django settings |
| 8 | + base_path = os.path.abspath(os.path.join(__file__, '..', '..')) |
| 9 | + sys.path.insert(0, base_path) |
| 10 | + os.environ['DJANGO_SETTINGS_MODULE'] = 'deis.settings' |
| 11 | + from api import models |
| 12 | + # deserialize build |
| 13 | + inp = sys.stdin.read() |
| 14 | + build = json.loads(inp) |
| 15 | + # pull username out of ssh key |
| 16 | + ssh_key = build.pop('ssh_key') |
| 17 | + username = ssh_key.split('_')[0] |
| 18 | + from django.contrib.auth.models import User |
| 19 | + u=User.objects.get(username=username) |
| 20 | + build['owner'] = u |
| 21 | + # lookup formation |
| 22 | + formation_id = build.pop('formation') |
| 23 | + formation = models.Formation.objects.get( |
| 24 | + owner=u, id=formation_id) |
| 25 | + build['formation'] = formation |
| 26 | + # create the new build |
| 27 | + b = models.Build.objects.create(**build) |
| 28 | + # send release signal |
| 29 | + models.release_signal.send(sender=b, |
| 30 | + build=b, formation=formation, user=u) |
| 31 | + # pull the formation again with the new release |
| 32 | + formation = models.Formation.objects.get( |
| 33 | + owner=u, id=formation_id) |
| 34 | + # calculate the formation and converge it |
| 35 | + databag = formation.calculate() |
| 36 | + formation.converge(databag) |
| 37 | + # return a json dump of the databag |
| 38 | + sys.stdout.write(json.dumps(databag)) |
| 39 | + sys.stdout.flush() |
| 40 | + sys.exit(0) |
0 commit comments