diff options
author | Scott Moser <smoser@ubuntu.com> | 2013-10-24 11:45:35 -0700 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2013-10-24 11:45:35 -0700 |
commit | c85279c930786384cd818d75a11922c24bd5fb1e (patch) | |
tree | dc01c220c6e664a83443eff3fe79f954495e4e35 /cloudinit/config | |
parent | b27fab81c99fcb05f4c633bad62d4151edc702e6 (diff) | |
download | vyos-cloud-init-c85279c930786384cd818d75a11922c24bd5fb1e.tar.gz vyos-cloud-init-c85279c930786384cd818d75a11922c24bd5fb1e.zip |
support calling add-apt-repository on cloud-archive: entries
LP: #1244355
Diffstat (limited to 'cloudinit/config')
-rw-r--r-- | cloudinit/config/cc_apt_configure.py | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/cloudinit/config/cc_apt_configure.py b/cloudinit/config/cc_apt_configure.py index 5a407016..7121ec43 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) + 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,7 +178,7 @@ def add_sources(srclist, template_params=None): continue source = ent['source'] - if source.startswith("ppa:"): + if aa_repo_match(source): try: util.subp(["add-apt-repository", source]) except: |