diff options
author | Scott Moser <smoser@ubuntu.com> | 2011-01-19 05:20:26 +0000 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2011-01-19 05:20:26 +0000 |
commit | 738766778c88bcfe692f8df17f91c4d5c6c90cdd (patch) | |
tree | 2562517fdbdfa818fa4b7ad1cdc3ea1071274349 | |
parent | b85106a10a78e4c15303ac3b9b16d03a3f2f9cab (diff) | |
download | vyos-cloud-init-738766778c88bcfe692f8df17f91c4d5c6c90cdd.tar.gz vyos-cloud-init-738766778c88bcfe692f8df17f91c4d5c6c90cdd.zip |
support $MIRROR and $RELEASE in apt-source cloud-config lines (LP: #693292)
sources can use $MIRROR and $RELEASE and they will be replaced
with the local mirror for this cloud, and the running release
this:
- source: deb $MIRROR $RELEASE multiverse
would possibly be turned into:
- source: deb http://us-east-1.ec2.archive.ubuntu.com/ubuntu natty multiverse
LP: #693292
-rw-r--r-- | cloudinit/CloudConfig/cc_apt_update_upgrade.py | 24 | ||||
-rw-r--r-- | cloudinit/util.py | 4 | ||||
-rw-r--r-- | doc/examples/cloud-config.txt | 6 |
3 files changed, 25 insertions, 9 deletions
diff --git a/cloudinit/CloudConfig/cc_apt_update_upgrade.py b/cloudinit/CloudConfig/cc_apt_update_upgrade.py index 396c5e09..e918e8c8 100644 --- a/cloudinit/CloudConfig/cc_apt_update_upgrade.py +++ b/cloudinit/CloudConfig/cc_apt_update_upgrade.py @@ -25,20 +25,23 @@ def handle(name,cfg,cloud,log,args): update = util.get_cfg_option_bool(cfg, 'apt_update', False) upgrade = util.get_cfg_option_bool(cfg, 'apt_upgrade', False) + release = get_release() + if cfg.has_key("apt_mirror"): + mirror = cfg["apt_mirror"] + else: + mirror = cloud.get_mirror() + if not util.get_cfg_option_bool(cfg, \ 'apt_preserve_sources_list', False): - if cfg.has_key("apt_mirror"): - mirror = cfg["apt_mirror"] - else: - mirror = cloud.get_mirror() - generate_sources_list(mirror) + generate_sources_list(release, mirror) old_mir = util.get_cfg_option_str(cfg,'apt_old_mirror', \ "archive.ubuntu.com/ubuntu") rename_apt_lists(old_mir, mirror) # process 'apt_sources' if cfg.has_key('apt_sources'): - errors = add_sources(cfg['apt_sources']) + errors = add_sources(cfg['apt_sources'], + { 'MIRROR' : mirror, 'RELEASE' : release } ) for e in errors: log.warn("Source Error: %s\n" % ':'.join(e)) @@ -96,17 +99,18 @@ def rename_apt_lists(omirror,new_mirror,lists_d="/var/lib/apt/lists"): for file in glob.glob("%s_*" % oprefix): os.rename(file,"%s%s" % (nprefix, file[olen:])) -def generate_sources_list(mirror): +def get_release(): stdout, stderr = subprocess.Popen(['lsb_release', '-cs'], stdout=subprocess.PIPE).communicate() - codename = stdout.strip() + return(stdout.strip()) +def generate_sources_list(codename, mirror): util.render_to_file('sources.list', '/etc/apt/sources.list', \ { 'mirror' : mirror, 'codename' : codename }) # srclist is a list of dictionaries, # each entry must have: 'source' # may have: key, ( keyid and keyserver) -def add_sources(srclist): +def add_sources(srclist, searchList={ }): elst = [] for ent in srclist: @@ -121,6 +125,8 @@ def add_sources(srclist): elst.append([source, "add-apt-repository failed"]) continue + source = util.render_string(source, searchList) + if not ent.has_key('filename'): ent['filename']='cloud_config_sources.list' diff --git a/cloudinit/util.py b/cloudinit/util.py index 7c9e60d5..d5ae2bec 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -136,6 +136,10 @@ def render_to_file(template, outfile, searchList): f.write(t.respond()) f.close() +def render_string(template, searchList): + return(Template(template, searchList=[searchList]).respond()) + + # read_optional_seed # returns boolean indicating success or failure (presense of files) # if files are present, populates 'fill' dictionary with 'user-data' and diff --git a/doc/examples/cloud-config.txt b/doc/examples/cloud-config.txt index 58082667..a32fd038 100644 --- a/doc/examples/cloud-config.txt +++ b/doc/examples/cloud-config.txt @@ -48,6 +48,12 @@ apt_sources: # See sources.list man page for more information about the format - source: deb http://archive.ubuntu.com/ubuntu karmic-backports main universe multiverse restricted + # sources can use $MIRROR and $RELEASE and they will be replaced + # with the local mirror for this cloud, and the running release + # the entry below would be possibly turned into: + # - source: deb http://us-east-1.ec2.archive.ubuntu.com/ubuntu natty multiverse + - source: deb $MIRROR $RELEASE multiverse + # this would have the same end effect as 'ppa:byobu/ppa' - source: "deb http://ppa.launchpad.net/byobu/ppa/ubuntu karmic main" keyid: F430BBA5 # GPG key ID published on a key server |