summaryrefslogtreecommitdiff
path: root/cloudinit/config/cc_apt_configure.py
diff options
context:
space:
mode:
authorChristian Ehrhardt <christian.ehrhardt@canonical.com>2016-05-12 15:51:21 +0200
committerChristian Ehrhardt <christian.ehrhardt@canonical.com>2016-05-12 15:51:21 +0200
commit0d8bf6f2c1464b5f4dab735841a50d02016d2caf (patch)
tree0d1f4384dbba71ce2b18325bf1b66883278a4640 /cloudinit/config/cc_apt_configure.py
parentcdee96acdde84071d54764e2554e6ee27702166c (diff)
downloadvyos-cloud-init-0d8bf6f2c1464b5f4dab735841a50d02016d2caf.tar.gz
vyos-cloud-init-0d8bf6f2c1464b5f4dab735841a50d02016d2caf.zip
add feature to allow a custom template for source list
Diffstat (limited to 'cloudinit/config/cc_apt_configure.py')
-rw-r--r--cloudinit/config/cc_apt_configure.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/cloudinit/config/cc_apt_configure.py b/cloudinit/config/cc_apt_configure.py
index 1d3eddff..2ab5e86c 100644
--- a/cloudinit/config/cc_apt_configure.py
+++ b/cloudinit/config/cc_apt_configure.py
@@ -21,6 +21,7 @@
import glob
import os
import re
+import tempfile
from cloudinit import templater
from cloudinit import util
@@ -70,7 +71,7 @@ def handle(name, cfg, cloud, log, _args):
if not util.get_cfg_option_bool(cfg,
'apt_preserve_sources_list', False):
- generate_sources_list(release, mirrors, cloud, log)
+ generate_sources_list(cfg, release, mirrors, cloud, log)
old_mirrors = cfg.get('apt_old_mirrors',
{"primary": "archive.ubuntu.com/ubuntu",
"security": "security.ubuntu.com/ubuntu"})
@@ -149,7 +150,17 @@ def get_release():
return stdout.strip()
-def generate_sources_list(codename, mirrors, cloud, log):
+def generate_sources_list(cfg, codename, mirrors, cloud, log):
+ params = {'codename': codename}
+ for k in mirrors:
+ params[k] = mirrors[k]
+
+ custtmpl = cfg.get('apt_custom_sources_list', None)
+ if custtmpl is not None:
+ templater.render_string_to_file(custtmpl,
+ '/etc/apt/sources.list', params)
+ return
+
template_fn = cloud.get_template_filename('sources.list.%s' %
(cloud.distro.name))
if not template_fn:
@@ -158,9 +169,6 @@ def generate_sources_list(codename, mirrors, cloud, log):
log.warn("No template found, not rendering /etc/apt/sources.list")
return
- params = {'codename': codename}
- for k in mirrors:
- params[k] = mirrors[k]
templater.render_to_file(template_fn, '/etc/apt/sources.list', params)