~brianlbaird/charms/trusty/pcrf/trunk

« back to all changes in this revision

Viewing changes to trusty/pcrf/reactive/docker.py

  • Committer: brian baird
  • Date: 2016-08-24 18:05:17 UTC
  • Revision ID: brianlbaird@gmail.com-20160824180517-uyp6100mfwuj6les
dt demo

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
from subprocess import check_call
 
3
 
 
4
from charmhelpers.core.hookenv import status_set
 
5
from charmhelpers.core.hookenv import config
 
6
 
 
7
from charms.reactive import set_state
 
8
from charms.reactive import hook
 
9
from charms.reactive import when
 
10
from charms.reactive import when_not
 
11
 
 
12
# 2 Major events are emitted from this layer.
 
13
#
 
14
# `docker.ready` is an event intended to signal other layers that need to
 
15
# plug into the plumbing to extend the docker daemon. Such as fire up a
 
16
# bootstrap docker daemon, or predependency fetch + dockeropt rendering
 
17
#
 
18
# `docker.available` means the docker daemon setup has settled and is prepared
 
19
# to run workloads. This is a broad state that has large implications should
 
20
# you decide to remove it. Production workloads can be lost if no restart flag
 
21
# is provided.
 
22
 
 
23
# Be sure you bind to it appropriately in your workload layer and
 
24
# react to the proper event.
 
25
 
 
26
 
 
27
@hook('install')
 
28
def install():
 
29
    ''' Install the docker daemon, and supporting tooling '''
 
30
    status_set('maintenance', 'Installing Docker and AUFS')
 
31
    # Using getenv will return '' if CHARM_DIR is not an environment variable.
 
32
    charm_path = os.getenv('CHARM_DIR', '')
 
33
    install_script_path = os.path.join(charm_path, 'scripts/install_docker.sh')
 
34
    check_call([install_script_path])
 
35
    status_set('active', 'Docker installed, cycling for extensions')
 
36
    set_state('docker.ready')
 
37
 
 
38
    # Install pip.
 
39
    check_call(['apt-get', 'install', '-y', 'python-pip'])
 
40
    # Pip install docker-compose.
 
41
    check_call(['pip', 'install', '-U', 'docker-compose'])
 
42
    # Leave a status message that Docker is installed.
 
43
 
 
44
    # Make with the adding of the users to the groups
 
45
    check_call(['usermod', '-aG', 'docker', 'ubuntu'])
 
46
 
 
47
 
 
48
@when('docker.ready')
 
49
@when_not('cgroups.modified')
 
50
def enable_grub_cgroups():
 
51
    cfg = config()
 
52
    if cfg.get('enable-cgroups'):
 
53
        check_call(['scripts/enable_grub_cgroups.sh'])
 
54
        set_state('cgroups.modified')
 
55
 
 
56
 
 
57
@when('docker.ready')
 
58
@when_not('docker.available')
 
59
def signal_workloads_start():
 
60
    ''' We can assume the pre-workload bits have completed now that docker.ready
 
61
    has been reacted to. Lets remove the predep work and continue on to being
 
62
    available '''
 
63
    status_set('active', 'Docker installed')
 
64
    set_state('docker.available')