summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2013-10-24 13:32:05 -0700
committerScott Moser <smoser@ubuntu.com>2013-10-24 13:32:05 -0700
commitf7d51c7ee1a7520a27a22cab6b0f350d5b5aaf8b (patch)
treed87bb250f7e52d5fa8cd8893ef0d308cc20cec2c /cloudinit
parentb27fab81c99fcb05f4c633bad62d4151edc702e6 (diff)
parent0473a7f4acacdfe2d9e3840a6f89399f60f7a9d2 (diff)
downloadvyos-cloud-init-f7d51c7ee1a7520a27a22cab6b0f350d5b5aaf8b.tar.gz
vyos-cloud-init-f7d51c7ee1a7520a27a22cab6b0f350d5b5aaf8b.zip
support calling add-apt-repository on cloud-archive: entries
LP: #1244355
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/config/cc_apt_configure.py30
1 files changed, 23 insertions, 7 deletions
diff --git a/cloudinit/config/cc_apt_configure.py b/cloudinit/config/cc_apt_configure.py
index 5a407016..b094ea22 100644
--- a/cloudinit/config/cc_apt_configure.py
+++ b/cloudinit/config/cc_apt_configure.py
@@ -20,6 +20,7 @@
import glob
import os
+import re
from cloudinit import templater
from cloudinit import util
@@ -30,6 +31,9 @@ PROXY_TPL = "Acquire::HTTP::Proxy \"%s\";\n"
APT_CONFIG_FN = "/etc/apt/apt.conf.d/94cloud-init-config"
APT_PROXY_FN = "/etc/apt/apt.conf.d/95cloud-init-proxy"
+# this will match 'XXX:YYY' (ie, 'cloud-archive:foo' or 'ppa:bar')
+ADD_APT_REPO_MATCH = r"^[\w-]+:\w"
+
# A temporary shell program to get a given gpg key
# from a given keyserver
EXPORT_GPG_KEYID = """
@@ -78,7 +82,15 @@ def handle(name, cfg, cloud, log, _args):
params = mirrors
params['RELEASE'] = release
params['MIRROR'] = mirror
- errors = add_sources(cfg['apt_sources'], params)
+
+ matchcfg = cfg.get('add_apt_repo_match', ADD_APT_REPO_MATCH)
+ if matchcfg:
+ matcher = re.compile(matchcfg).search
+ else:
+ matcher = lambda f: False
+
+ errors = add_sources(cfg['apt_sources'], params,
+ aa_repo_match=matcher)
for e in errors:
log.warn("Add source error: %s", ':'.join(e))
@@ -147,7 +159,7 @@ def generate_sources_list(codename, mirrors, cloud, log):
templater.render_to_file(template_fn, '/etc/apt/sources.list', params)
-def add_sources(srclist, template_params=None):
+def add_sources(srclist, template_params=None, aa_repo_match=None):
"""
add entries in /etc/apt/sources.list.d for each abbreviated
sources.list entry in 'srclist'. When rendering template, also
@@ -156,6 +168,9 @@ def add_sources(srclist, template_params=None):
if template_params is None:
template_params = {}
+ if aa_repo_match is None:
+ aa_repo_match = lambda f: False
+
errorlist = []
for ent in srclist:
if 'source' not in ent:
@@ -163,15 +178,16 @@ def add_sources(srclist, template_params=None):
continue
source = ent['source']
- if source.startswith("ppa:"):
+ source = templater.render_string(source, template_params)
+
+ if aa_repo_match(source):
try:
util.subp(["add-apt-repository", source])
- except:
- errorlist.append([source, "add-apt-repository failed"])
+ except util.ProcessExecutionError as e:
+ errorlist.append([source,
+ ("add-apt-repository failed. " + str(e))])
continue
- source = templater.render_string(source, template_params)
-
if 'filename' not in ent:
ent['filename'] = 'cloud_config_sources.list'