diff options
author | Scott Moser <smoser@ubuntu.com> | 2010-03-08 12:51:34 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2010-03-08 12:51:34 -0500 |
commit | 7ce3e129b3ae3caed01d2945cece75b953c452e6 (patch) | |
tree | c426f1dd8908fd8bc420703393b7bcd714dafce3 /cloudinit | |
parent | ee291edfccd67e97f2f8f4129168279e5f0499b3 (diff) | |
download | vyos-cloud-init-7ce3e129b3ae3caed01d2945cece75b953c452e6.tar.gz vyos-cloud-init-7ce3e129b3ae3caed01d2945cece75b953c452e6.zip |
rename apt lists files to match newly selected mirror (LP: #513060)
On first boot of an instance, cloud-config replaces
/etc/apt/sources.list with references to a local mirror. This will also
rename the old list files in /var/lib/apt/lists .
LP: #513060
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/CloudConfig.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/cloudinit/CloudConfig.py b/cloudinit/CloudConfig.py index 487e9872..3f965f39 100644 --- a/cloudinit/CloudConfig.py +++ b/cloudinit/CloudConfig.py @@ -115,6 +115,9 @@ class CloudConfig(): else: mirror = self.cloud.get_mirror() generate_sources_list(mirror) + old_mir = util.get_cfg_option_str(self.cfg,'apt_old_mirror', \ + "archive.ubuntu.com/ubuntu") + rename_apt_lists(old_mir, mirror) # process 'apt_sources' if self.cfg.has_key('apt_sources'): @@ -539,3 +542,22 @@ def handle_runcmd(cfg): util.write_file(outfile,content,0700) except: warn("failed to open %s for runcmd" % outfile) + +def mirror2lists_fileprefix(mirror): + file=mirror + # take of http:// or ftp:// + if file.endswith("/"): file=file[0:-1] + pos=file.find("://") + if pos >= 0: + file=file[pos+3:] + file=file.replace("/","_") + return file + +def rename_apt_lists(omirror,new_mirror,lists_d="/var/lib/apt/lists"): + + oprefix="%s/%s" % (lists_d,mirror2lists_fileprefix(omirror)) + nprefix="%s/%s" % (lists_d,mirror2lists_fileprefix(new_mirror)) + if(oprefix==nprefix): return + olen=len(oprefix) + for file in glob.glob("%s_*" % oprefix): + os.rename(file,"%s%s" % (nprefix, file[olen:])) |