diff options
-rw-r--r-- | debian/init | 11 | ||||
-rwxr-xr-x | ec2-set-apt-sources.py | 53 | ||||
-rwxr-xr-x | ec2-set-defaults.py | 46 | ||||
-rw-r--r-- | ec2init/__init__.py | 21 | ||||
-rwxr-xr-x | setup.py | 1 |
5 files changed, 42 insertions, 90 deletions
diff --git a/debian/init b/debian/init index dd363ee0..b2995b79 100644 --- a/debian/init +++ b/debian/init @@ -116,17 +116,6 @@ case "$1" in log_end_msg 1 fi - if run_once_ever apt_source_list - then - log_daemon_msg "Creating /etc/apt/sources.list" - if ec2-set-apt-sources 2> /dev/null - then - log_end_msg 0 - else - log_end_msg 1 - fi - fi - if run_once_per_instance user-data then log_daemon_msg "Running EC2 user data" diff --git a/ec2-set-apt-sources.py b/ec2-set-apt-sources.py deleted file mode 100755 index 8bc89312..00000000 --- a/ec2-set-apt-sources.py +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/python -# -# Fetch the availabity zone and create the sources.list -# Copyright (C) 2009 Canonical Ltd. -# -# Author: Chuck Short <chuck.short@canonical.com> -# Soren Hansen <soren@canonical.com> -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 3, as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# -import os -import subprocess -from Cheetah.Template import Template - -import ec2init - -SOURCES_LIST = '/etc/apt/sources.list' -GENERATED_SOURCES_LIST = '/var/run/ec2/sources.list' -OUT_OF_THE_WAY_SOURCES_LIST = '/etc/apt/sources.list.moved-by-ec2-init' - -def main(): - ec2 = ec2init.EC2Init() - - mirror = ec2.get_mirror_for_availability_zone() - - if not os.path.exists(GENERATED_SOURCES_LIST): - t = os.popen("lsb_release -cs").read() - codename = t.strip() - - mp = { 'mirror' : mirror, 'codename' : codename } - t = Template(file='/etc/ec2-init/templates/sources.list.tmpl', searchList=[mp]) - f = open(GENERATED_SOURCES_LIST, 'w') - f.write(t.respond()) - f.close() - - if not os.path.exists(OUT_OF_THE_WAY_SOURCES_LIST): - os.rename(SOURCES_LIST, OUT_OF_THE_WAY_SOURCES_LIST) - os.symlink(GENERATED_SOURCES_LIST, SOURCES_LIST) - aptget = subprocess.Popen(['apt-get', 'update']) - aptget.communicate() - -if __name__ == '__main__': - main() diff --git a/ec2-set-defaults.py b/ec2-set-defaults.py index f6d6a038..878d4889 100755 --- a/ec2-set-defaults.py +++ b/ec2-set-defaults.py @@ -3,8 +3,8 @@ # Fetch the availabity zone and create the sources.list # Copyright (C) 2008-2009 Canonical Ltd. # -# Author: Chuck Short <chuck.short@canonical.com> -# Soren Hansen <soren@canonical.com> +# Authors: Chuck Short <chuck.short@canonical.com> +# Soren Hansen <soren@canonical.com> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3, as @@ -23,31 +23,31 @@ import subprocess import ec2init -def get_location_from_availability_zone(availability_zone): - if availability.startswith('us-'): - return 'us' - elif availability.startswith('eu-'): - return 'eu' - raise Exception('Could not determine location') - -location_archive_map = { - 'us' : 'http://us.ec2.archive.ubuntu.com/ubuntu', - 'eu' : 'http://eu.ec2.archive.ubuntu.com/ubuntu' -} - -location_locale_map = { - 'us' : 'en_US.UTF-8', - 'eu' : 'en_GB.UTF-8' -} - def main(): ec2 = ec2init.EC2Init() - location = get_location_from_availability_zone(ec2.get_availability_zone()) + availability_zone = ec2.get_availability_zone() + location = ec2.get_location_from_availability_zone(availability_zone) + mirror = ec2.get_mirror_from_availability_zone(availability_zone) + + locale = ec2.location_locale_map[location] + apply_locale(locale) + + generate_sources_list(mirror) + +def apply_locale(locale): + subprocess.Popen(['locale-gen', locale]).communicate() + subprocess.Popen(['update-locale', locale]).communicate() + +def generate_sources_list(self, mirror) + stdout, stderr = subprocess.Popen(['lsb_release', '-cs'], stdout=subprocess.PIPE).communicate() + codename = stdout.strip() - locale = location_locale_map[location] - subprocess.Popen(['locale-gen', locale]).communicate() - subprocess.Popen(['update-locale', locale]).communicate() + mp = { 'mirror' : mirror, 'codename' : codename } + t = Template(file='/etc/ec2-init/templates/sources.list.tmpl', searchList=[mp]) + f = open(SOURCES_LIST, 'w') + f.write(t.respond()) + f.close() if __name__ == '__main__': main() diff --git a/ec2init/__init__.py b/ec2init/__init__.py index 729e3a48..c8e7ba2f 100644 --- a/ec2init/__init__.py +++ b/ec2init/__init__.py @@ -73,8 +73,7 @@ class EC2Init(): def get_hostname(self): return self.get_instance_metadata()['local-hostname'] - def get_mirror_for_availability_zone(self): - availability_zone = self.get_availability_zone() + def get_mirror_from_availability_zone(self, availability_zone): if zone.startswith("us"): return 'http://us.ec2.archive.ubuntu.com/ubuntu/' elif zone.startswith("eu"): @@ -97,3 +96,21 @@ class EC2Init(): time.sleep(timeout) timeout = timeout * 2 return False + + def get_location_from_availability_zone(availability_zone): + if availability.startswith('us-'): + return 'us' + elif availability.startswith('eu-'): + return 'eu' + raise Exception('Could not determine location') + +location_locale_map = { + 'us' : 'en_US.UTF-8', + 'eu' : 'en_GB.UTF-8' +} + +location_archive_map = { + 'us' : 'http://us.ec2.archive.ubuntu.com/ubuntu', + 'eu' : 'http://eu.ec2.archive.ubuntu.com/ubuntu' +} + @@ -32,7 +32,6 @@ setup(name='EC2-init', scripts=['ec2-fetch-credentials.py', 'ec2-get-info.py', 'ec2-run-user-data.py', - 'ec2-set-apt-sources.py', 'ec2-set-defaults.py', 'ec2-set-hostname.py', 'ec2-wait-for-meta-data-service.py'], |