diff options
author | Scott Moser <smoser@ubuntu.com> | 2010-01-26 16:40:10 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2010-01-26 16:40:10 -0500 |
commit | 63ba097865e1d038d82a7fa1d6efd282784677f5 (patch) | |
tree | 1616db14a425c16c1b52d8cda6442b6eef52c536 | |
parent | af394388ff0985b4b407ed4faeb105395655d102 (diff) | |
download | vyos-cloud-init-63ba097865e1d038d82a7fa1d6efd282784677f5.tar.gz vyos-cloud-init-63ba097865e1d038d82a7fa1d6efd282784677f5.zip |
move writing sources.list to CloudConfig. add 'apt_preserve_sources_list'
Move the writing of sources.list to CloudConfig. This way we have
access to the cloud-config user data. Then, allow the user
to specify the archive mirror using 'apt_mirror' key.
Now, if specified in cloud-config, that is used, otherwise, we
get one from the DataSource.
One other change here is adding 'apt_preserve_sources_list'. If set to
true, then overwriting of the sources.list with the selected mirror
will not be done.
-rwxr-xr-x | ec2-init.py | 18 | ||||
-rw-r--r-- | ec2init/CloudConfig.py | 15 | ||||
-rw-r--r-- | ec2init/__init__.py | 9 | ||||
-rw-r--r-- | ec2init/util.py | 8 |
4 files changed, 35 insertions, 15 deletions
diff --git a/ec2-init.py b/ec2-init.py index 66fd62e2..7597e9c6 100755 --- a/ec2-init.py +++ b/ec2-init.py @@ -1,10 +1,10 @@ #!/usr/bin/python import subprocess -from Cheetah.Template import Template import sys import ec2init +import ec2init.util as util def warn(str): sys.stderr.write(str) @@ -56,27 +56,15 @@ def main(): sys.exit(0) -def render_to_file(template, outfile, searchList): - t = Template(file='/etc/ec2-init/templates/%s.tmpl' % template, searchList=[searchList]) - f = open(outfile, 'w') - f.write(t.respond()) - f.close() - def set_defaults(cloud): - generate_sources_list(cloud.get_mirror()) apply_locale(cloud.get_locale()) def apply_locale(locale): subprocess.Popen(['locale-gen', locale]).communicate() subprocess.Popen(['update-locale', locale]).communicate() - render_to_file('default-locale', '/etc/default/locale', { 'locale' : locale }) - -def generate_sources_list(mirror): - stdout, stderr = subprocess.Popen(['lsb_release', '-cs'], stdout=subprocess.PIPE).communicate() - codename = stdout.strip() - - render_to_file('sources.list', '/etc/apt/sources.list', { 'mirror' : mirror, 'codename' : codename }) + util.render_to_file('default-locale', '/etc/default/locale', \ + { 'locale' : locale }) if __name__ == '__main__': main() diff --git a/ec2init/CloudConfig.py b/ec2init/CloudConfig.py index 6c661260..51618943 100644 --- a/ec2init/CloudConfig.py +++ b/ec2init/CloudConfig.py @@ -99,6 +99,13 @@ class CloudConfig(): update = util.get_cfg_option_bool(self.cfg, 'apt_update', False) upgrade = util.get_cfg_option_bool(self.cfg, 'apt_upgrade', False) + if not util.get_cfg_option_bool(self.cfg, \ + 'apt_preserve_sources_list', False): + if self.cfg.has_key("apt_mirror"): + mirror = self.cfg["apt_mirror"] + else: + mirror = self.cloud.get_mirror() + generate_sources_list(mirror) # process 'apt_sources' if self.cfg.has_key('apt_sources'): @@ -277,3 +284,11 @@ def add_sources(srclist): elst.append([source, "failed write to file %s" % ent['filename']]) return(elst) + + +def generate_sources_list(mirror): + stdout, stderr = subprocess.Popen(['lsb_release', '-cs'], stdout=subprocess.PIPE).communicate() + codename = stdout.strip() + + util.render_to_file('sources.list', '/etc/apt/sources.list', \ + { 'mirror' : mirror, 'codename' : codename }) diff --git a/ec2init/__init__.py b/ec2init/__init__.py index f89839ab..c4923f1b 100644 --- a/ec2init/__init__.py +++ b/ec2init/__init__.py @@ -260,6 +260,15 @@ class EC2Init: f=open(cloud_config, "wb") f.write(self.cloud_config_str) f.close() + + ## this could merge the cloud config with the system config + ## for now, not doing this as it seems somewhat circular + ## as CloudConfig does that also, merging it with this cfg + ## + # ccfg = yaml.load(self.cloud_config_str) + # if ccfg is None: ccfg = { } + # self.cfg = util.mergedict(ccfg, self.cfg) + return self.cloud_config_str+="\n#%s\n%s" % (filename,payload) diff --git a/ec2init/util.py b/ec2init/util.py index ece5755a..403832ff 100644 --- a/ec2init/util.py +++ b/ec2init/util.py @@ -2,6 +2,7 @@ import yaml import os import errno import subprocess +from Cheetah.Template import Template def read_conf(fname): stream = file(fname) @@ -69,3 +70,10 @@ def subp(args, input=None): if sp.returncode is not 0: raise subprocess.CalledProcessError(sp.returncode,args) return(out,err) + +def render_to_file(template, outfile, searchList): + t = Template(file='/etc/ec2-init/templates/%s.tmpl' % template, searchList=[searchList]) + f = open(outfile, 'w') + f.write(t.respond()) + f.close() + |