~charmers/charms/precise/buildbot-master/trunk

« back to all changes in this revision

Viewing changes to hooks/buildbot-relation-changed

  • Committer: Francesco Banconi
  • Date: 2012-02-07 14:37:13 UTC
  • mfrom: (11.1.8 dynamic-relationship)
  • Revision ID: francesco.banconi@canonical.com-20120207143713-7ycviq0xpp8roffy
Merged branch dynamic-relationship and added cleanup fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
# Copyright 2012 Canonical Ltd.  This software is licensed under the
 
4
# GNU Affero General Public License version 3 (see the file LICENSE).
 
5
 
 
6
from helpers import (
 
7
    log,
 
8
    relation_get,
 
9
    relation_set,
 
10
    )
 
11
from local import (
 
12
    buildbot_reconfig,
 
13
    generate_string,
 
14
    slave_json,
 
15
    )
 
16
 
 
17
 
 
18
def get_or_create(key, prefix=''):
 
19
    log("Retrieving {}.".format(key))
 
20
    value = relation_get(key)
 
21
    if not value:
 
22
        log("Generating {}.".format(key))
 
23
        value = generate_string(prefix)
 
24
    log("{}: {}".format(key, value))
 
25
    return value
 
26
 
 
27
 
 
28
def update_slave_json(builders, name, passwd):
 
29
    slave_info = slave_json.get()
 
30
    slave_info[name] = (passwd, builders)
 
31
    slave_json.set(slave_info)
 
32
 
 
33
 
 
34
def main():
 
35
    log("Retrieving builders.")
 
36
    builders = filter(
 
37
        None,
 
38
        (b.strip() for b in relation_get('builders').split(',')))
 
39
    log("builders: {}".format(builders))
 
40
    name = get_or_create('name', prefix='slave-')
 
41
    passwd = get_or_create('passwd')
 
42
    update_slave_json(builders, name, passwd)
 
43
    log("Reconfiguring buildbot.")
 
44
    buildbot_reconfig()
 
45
    log("Sending name and password to the slave.")
 
46
    relation_set(name=name, passwd=passwd)
 
47
 
 
48
 
 
49
if __name__ == '__main__':
 
50
    log('BUILDBOT-RELATION-CHANGED HOOK:')
 
51
    main()