~junaidali/charms/trusty/plumgrid-director/pg-restart

« back to all changes in this revision

Viewing changes to hooks/pg_dir_hooks.py

  • Committer: bbaqar at plumgrid
  • Date: 2015-07-29 18:07:31 UTC
  • Revision ID: bbaqar@plumgrid.com-20150729180731-ioynar8x3u5pxytc
Addressed reviews by Charmers

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
 
3
# Copyright (c) 2015, PLUMgrid Inc, http://plumgrid.com
 
4
 
 
5
# The hooks of this charm have been symlinked to functions
 
6
# in this file.
 
7
 
3
8
import sys
4
9
 
5
10
from charmhelpers.core.hookenv import (
6
11
    Hooks,
7
12
    UnregisteredHookError,
8
 
    config,
9
13
    log,
10
 
    relation_set,
 
14
)
 
15
 
 
16
from charmhelpers.fetch import (
 
17
    apt_install,
 
18
    apt_purge,
 
19
    configure_sources,
11
20
)
12
21
 
13
22
from pg_dir_utils import (
15
24
    ensure_files,
16
25
    restart_pg,
17
26
    stop_pg,
 
27
    determine_packages,
 
28
    load_iovisor,
 
29
    remove_iovisor,
 
30
    ensure_mtu,
 
31
    add_lcm_key,
18
32
)
19
33
 
20
34
hooks = Hooks()
23
37
 
24
38
@hooks.hook()
25
39
def install():
 
40
    '''
 
41
    Install hook is run when the charm is first deployed on a node.
 
42
    '''
 
43
    configure_sources(update=True)
 
44
    pkgs = determine_packages()
 
45
    for pkg in pkgs:
 
46
        apt_install(pkg, options=['--force-yes'], fatal=True)
 
47
    load_iovisor()
 
48
    ensure_mtu()
26
49
    ensure_files()
 
50
    add_lcm_key()
27
51
 
28
52
 
29
53
@hooks.hook('plumgrid-plugin-relation-joined')
30
54
def plumgrid_dir():
31
 
    ensure_files()
32
 
    CONFIGS.write_all()
33
 
    restart_pg()
34
 
 
35
 
 
36
 
@hooks.hook('plumgrid-relation-joined')
37
 
def plumgrid_joined(relation_id=None):
38
 
    #We can pass information to the edge and gateway from there.
39
 
    relation_data = {
40
 
        'pg_virtual_ip': config('plumgrid-virtual-ip'),
41
 
    }
42
 
    relation_set(relation_id=relation_id, **relation_data)
 
55
    '''
 
56
    This hook is run when relation between neutron-api-plumgrid
 
57
    and plumgrid-director is made.
 
58
    '''
 
59
    ensure_mtu()
 
60
    ensure_files()
 
61
    add_lcm_key()
 
62
    CONFIGS.write_all()
 
63
    restart_pg()
 
64
 
 
65
 
 
66
@hooks.hook('config-changed')
 
67
def config_changed():
 
68
    '''
 
69
    This hook is run when a config parameter is changed.
 
70
    It also runs on node reboot.
 
71
    '''
 
72
    stop_pg()
 
73
    configure_sources(update=True)
 
74
    pkgs = determine_packages()
 
75
    for pkg in pkgs:
 
76
        apt_install(pkg, options=['--force-yes'], fatal=True)
 
77
    load_iovisor()
 
78
    ensure_mtu()
 
79
    ensure_files()
 
80
    add_lcm_key()
 
81
    CONFIGS.write_all()
 
82
    restart_pg()
43
83
 
44
84
 
45
85
@hooks.hook('stop')
46
86
def stop():
 
87
    '''
 
88
    This hook is run when the charm is destroyed.
 
89
    '''
47
90
    stop_pg()
 
91
    remove_iovisor()
 
92
    pkgs = determine_packages()
 
93
    for pkg in pkgs:
 
94
        apt_purge(pkg, fatal=False)
48
95
 
49
96
 
50
97
def main():