3
# Copyright 2012 Canonical Ltd.
6
# James Page <james.page@canonical.com>
8
# Taken from lp:~james-page/charms/precise/ganglia/python-refactor
23
subprocess.check_call(cmd)
25
TEMPLATES_DIR="templates"
30
install('python-jinja2')
33
def render_template (template_name, context, template_dir=TEMPLATES_DIR):
34
templates = jinja2.Environment(loader=jinja2.FileSystemLoader(template_dir))
35
template = templates.get_template(template_name)
36
return template.render(context)
38
def configure_source():
39
source = config_get("source")
40
if (source.startswith("ppa:") or
41
source.startswith("cloud:") or
42
source.startswith("http:")):
47
subprocess.check_call(cmd)
48
if source.startswith("http:"):
49
key = config_get("key")
55
subprocess.check_call(cmd)
60
subprocess.check_call(cmd)
66
def expose(port, protocol="TCP"):
69
"%d/%s" % (port,protocol)
71
subprocess.check_call(cmd)
73
def juju_log(message,severity="INFO"):
76
"--log-level", severity,
79
subprocess.check_call(cmd)
81
def relation_ids(relation):
86
return subprocess.check_output(cmd).split()
88
def relation_list(rid):
93
return subprocess.check_output(cmd).split()
95
def relation_get(attribute,unit=None,rid=None):
102
cmd.append(attribute)
105
return subprocess.check_output(cmd).strip()
107
def relation_set(*kwargs):
111
for k, v in kwargs.items():
112
cmd.append("%s=%s" % (k,v))
113
subprocess.check_call(cmd)
115
def unit_get(attribute):
120
return subprocess.check_output(cmd).strip()
122
def config_get(attribute):
127
return subprocess.check_output(cmd).strip()
129
def juju_log(level, message):
130
subprocess.call(['juju-log', '-l', level, message])