~barryprice/charms/trusty/thruk-master/trunk

« back to all changes in this revision

Viewing changes to hooks/actions.py

  • Committer: Brad Marshall
  • Date: 2015-05-28 04:07:25 UTC
  • Revision ID: brad.marshall@canonical.com-20150528040725-ck0h61lhl3jahada
[bradm] Handle changing the ppa

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from charmhelpers.core import hookenv
 
2
from charmhelpers.fetch import (
 
3
    apt_install, apt_update, add_source
 
4
)
2
5
import subprocess
3
6
import os
4
7
import base64
12
15
    return str(subprocess.check_output(['pwgen', '-s', '16'])).strip()
13
16
 
14
17
 
 
18
def update_ppa():
 
19
    config = hookenv.config()
 
20
 
 
21
    if config.changed('source'):
 
22
        prev_ppa = config.previous('source')
 
23
        if prev_ppa is not None:
 
24
            subprocess.check_call(['add-apt-repository', '--yes', '--remove', prev_ppa])
 
25
        ppa = config.get('source')
 
26
        if ppa is not None:
 
27
            add_source(ppa)
 
28
            apt_update()
 
29
            apt_install(["thruk"])
 
30
 
 
31
 
15
32
def thruk_set_password(service_name):
16
33
    passwd_file = "/var/lib/thruk/thrukadmin.passwd"
17
34
    if not os.path.exists(passwd_file):