~matsubara/charm-helpers/oil-charm-helpers

« back to all changes in this revision

Viewing changes to charmhelpers/canonical_ci/jenkins.py

  • Committer: yolanda.robla at canonical
  • Date: 2013-10-14 12:15:01 UTC
  • Revision ID: yolanda.robla@canonical.com-20131014121501-w462p64u5dlxaqqp
added jenkins utils

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import logging
 
2
import os
 
3
import paramiko
 
4
import sys
 
5
import subprocess
 
6
import json
 
7
 
 
8
from charmhelpers.core.hookenv import (
 
9
    log as _log,
 
10
    ERROR,
 
11
)
 
12
 
 
13
JENKINS_DAEMON = "/etc/init.d/jenkins"
 
14
 
 
15
logging.basicConfig(level=logging.INFO)
 
16
 
 
17
 
 
18
def log(msg, level=None):
 
19
    # wrap log calls and distribute to correct logger
 
20
    # depending if this code is being run by a hook
 
21
    # or an external script.
 
22
    if os.getenv('JUJU_AGENT_SOCKET'):
 
23
        _log(msg, level=level)
 
24
    else:
 
25
        logging.info(msg)
 
26
 
 
27
 
 
28
# start jenkins application
 
29
def start_jenkins():
 
30
    try:
 
31
        subprocess.check_call([JENKINS_DAEMON, "start"])
 
32
    except:
 
33
        pass
 
34
 
 
35
 
 
36
# stop jenkins application
 
37
def stop_jenkins():
 
38
    try:
 
39
        subprocess.check_call([JENKINS_DAEMON, "stop"])
 
40
    except:
 
41
        pass