9
8
from charmhelpers.core.hookenv import (
10
9
Hooks, UnregisteredHookError, log, local_unit)
11
from charmhelpers.fetch import (
12
apt_install, _run_apt_command, add_source, apt_update)
13
from charmhelpers.core.hookenv import config
14
10
from shutil import rmtree
15
11
from subprocess import CalledProcessError
32
@hooks.hook("install")
34
charm_config = config()
35
apt_install(["apt-transport-https", "wget"])
37
origin = charm_config.get("origin")
38
if origin == "distro":
41
if origin is not None:
42
add_apt_source(origin)
45
apt_install(["landscape-client"])
46
data_path = charm_config.get("data-path")
48
data_path = "/var/lib/landscape/client"
50
result = subprocess.call(["landscape-config", "--init", "-d", data_path])
52
result = subprocess.check_call([
53
"install", "-o", "landscape", "-g", "root", "-m", "755", "-d",
57
28
@hooks.hook("registration-relation-joined", "registration-relation-changed")
58
29
def registration_relation(juju_broker=JUJU_BROKER,
59
30
landscape_broker=LANDSCAPE_BROKER):
233
def build_from_launchpad(url):
234
"""The charm will install the code from the passed lp branch.
236
apt_install(["devscripts", "bzr", "pbuilder"], fatal=True)
237
subprocess.check_call(["rm", "-rf", "landscape-client-source"])
238
subprocess.check_call(["bzr", "branch", url, "landscape-client-source"])
239
os.chdir("landscape-client-source")
240
subprocess.check_call("/usr/lib/pbuilder/pbuilder-satisfydepends")
241
env = {"DEBUILD_OPTS": "-uc -us"}
242
subprocess.check_call(["make", "package"], env=env)
243
#TODO: The following call should be retried (potential race condition to
244
# acquire the dpkg lock).
245
subprocess.call(["dpkg", "-i", "../landscape-client_*.deb",
246
"../landscape-common_*.deb"])
247
# The _run_apt_command will ensure the command is retried in case we cannot
248
# acquire the lock for some reason.
249
_run_apt_command(["apt-get", "-f", "install"], fatal=True)
253
def add_apt_source(url):
254
"""Add an apt source entry, with passed in key.
256
This is a thin wrapper over the charmhelper "add_source" method to allow
257
for the URLs to contain the key explicitely, like:
258
- https://blah/blah|KEY
259
- deb https://blah/blah|KEY
263
if url.startswith("lp"):
264
return build_from_launchpad(url)
267
# We have a particular key specified. Url = url without the key now.
268
url, key = url.split("|", 1) # Maximum of 1 split.
270
log("Archive key for '%s' is empty.", level="WARNING")
272
return add_source(url, key)
275
204
def _write_certificate(certificate, filename):
277
206
@param certificate Text of the certificate, base64 encoded.