~aisrael/charm-tools/lp1305337

« back to all changes in this revision

Viewing changes to charmtools/templates/python/files/hooks_symlinked/hooks.py

  • Committer: Tim Van Steenburgh
  • Date: 2014-09-26 15:09:14 UTC
  • mfrom: (337.2.3 1.3)
  • Revision ID: tim.van.steenburgh@canonical.com-20140926150914-6iulcky6yl6i4l2d
Add ansible charm-create template; remove symlinked hook option

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
 
3
 
import os
4
 
import sys
5
 
 
6
 
sys.path.insert(0, os.path.join(os.environ['CHARM_DIR'], 'lib'))
7
 
 
8
 
from charmhelpers.core import (
9
 
    hookenv,
10
 
    host,
11
 
)
12
 
 
13
 
hooks = hookenv.Hooks()
14
 
log = hookenv.log
15
 
 
16
 
SERVICE = '$metadata.package'
17
 
 
18
 
 
19
 
@hooks.hook('install')
20
 
def install():
21
 
    log('Installing $metadata.package')
22
 
 
23
 
 
24
 
@hooks.hook('config-changed')
25
 
def config_changed():
26
 
    config = hookenv.config()
27
 
 
28
 
    for key in config:
29
 
        if config.changed(key):
30
 
            log("config['{}'] changed from {} to {}".format(
31
 
                key, config.previous(key), config[key]))
32
 
 
33
 
    config.save()
34
 
    start()
35
 
 
36
 
 
37
 
@hooks.hook('upgrade-charm')
38
 
def upgrade_charm():
39
 
    log('Upgrading $metadata.package')
40
 
 
41
 
 
42
 
@hooks.hook('start')
43
 
def start():
44
 
    host.service_restart(SERVICE) or host.service_start(SERVICE)
45
 
 
46
 
 
47
 
@hooks.hook('stop')
48
 
def stop():
49
 
    host.service_stop(SERVICE)
50
 
 
51
 
 
52
 
if __name__ == "__main__":
53
 
    # execute a hook based on the name the program is called by
54
 
    hooks.execute(sys.argv)