~smoser/ec2-init/ec2-init.devel

« back to all changes in this revision

Viewing changes to ec2init/CloudConfig.py

  • Committer: Scott Moser
  • Date: 2010-01-26 21:40:10 UTC
  • Revision ID: smoser@ubuntu.com-20100126214010-6jkp07u571wfeun1
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.

Show diffs side-by-side

added added

removed removed

Lines of Context:
99
99
        update = util.get_cfg_option_bool(self.cfg, 'apt_update', False)
100
100
        upgrade = util.get_cfg_option_bool(self.cfg, 'apt_upgrade', False)
101
101
 
 
102
        if not util.get_cfg_option_bool(self.cfg, \
 
103
            'apt_preserve_sources_list', False):
 
104
            if self.cfg.has_key("apt_mirror"):
 
105
                mirror = self.cfg["apt_mirror"]
 
106
            else:
 
107
                mirror = self.cloud.get_mirror()
 
108
            generate_sources_list(mirror)
102
109
 
103
110
        # process 'apt_sources'
104
111
        if self.cfg.has_key('apt_sources'):
277
284
            elst.append([source, "failed write to file %s" % ent['filename']])
278
285
 
279
286
    return(elst)
 
287
 
 
288
 
 
289
def generate_sources_list(mirror):
 
290
    stdout, stderr = subprocess.Popen(['lsb_release', '-cs'], stdout=subprocess.PIPE).communicate()
 
291
    codename = stdout.strip()
 
292
 
 
293
    util.render_to_file('sources.list', '/etc/apt/sources.list', \
 
294
        { 'mirror' : mirror, 'codename' : codename })