diff --git a/bootstrapvz/base/bootstrapinfo.py b/bootstrapvz/base/bootstrapinfo.py index 8edb5e8..0313e3b 100644 --- a/bootstrapvz/base/bootstrapinfo.py +++ b/bootstrapvz/base/bootstrapinfo.py @@ -31,11 +31,8 @@ class BootstrapInformation(object): # The default apt mirror self.apt_mirror = self.manifest.packages.get('mirror', 'http://http.debian.net/debian') - # Normalize the release codenames so that tasks may query for release codenames rather than - # 'stable', 'unstable' etc. This is useful when handling cases that are specific to a release. - release_codenames_path = os.path.join(os.path.dirname(__file__), 'release-codenames.yml') - from bootstrapvz.common.tools import config_get - self.release_codename = config_get(release_codenames_path, [self.manifest.system['release']]) + from bootstrapvz.common.tools import get_codename + self.release_codename = get_codename(self.manifest.system['release']) # Create the manifest_vars dictionary self.manifest_vars = self.__create_manifest_vars(self.manifest, {'apt_mirror': self.apt_mirror}) diff --git a/bootstrapvz/base/release-codenames.yml b/bootstrapvz/common/release-codenames.yml similarity index 100% rename from bootstrapvz/base/release-codenames.yml rename to bootstrapvz/common/release-codenames.yml diff --git a/bootstrapvz/common/tasks/initd.py b/bootstrapvz/common/tasks/initd.py index fdc14f5..ccf9119 100644 --- a/bootstrapvz/common/tasks/initd.py +++ b/bootstrapvz/common/tasks/initd.py @@ -45,7 +45,7 @@ class RemoveHWClock(Task): @classmethod def run(cls, info): info.initd['disable'].append('hwclock.sh') - if info.manifest.system['release'] == 'squeeze': + if info.release_codename == 'squeeze': info.initd['disable'].append('hwclockfirst.sh') diff --git a/bootstrapvz/common/tasks/ssh.py b/bootstrapvz/common/tasks/ssh.py index 242330d..354e95b 100644 --- a/bootstrapvz/common/tasks/ssh.py +++ b/bootstrapvz/common/tasks/ssh.py @@ -30,7 +30,7 @@ class AddSSHKeyGeneration(Task): try: log_check_call(['chroot', info.root, 'dpkg-query', '-W', 'openssh-server']) - if info.manifest.system['release'] == 'squeeze': + if info.release_codename == 'squeeze': install['generate-ssh-hostkeys'] = os.path.join(init_scripts_dir, 'squeeze/generate-ssh-hostkeys') else: install['generate-ssh-hostkeys'] = os.path.join(init_scripts_dir, 'generate-ssh-hostkeys') @@ -70,7 +70,7 @@ class ShredHostkeys(Task): def run(cls, info): ssh_hostkeys = ['ssh_host_dsa_key', 'ssh_host_rsa_key'] - if info.manifest.system['release'] != 'squeeze': + if info.release_codename != 'squeeze': ssh_hostkeys.append('ssh_host_ecdsa_key') private = [os.path.join(info.root, 'etc/ssh', name) for name in ssh_hostkeys] diff --git a/bootstrapvz/common/tools.py b/bootstrapvz/common/tools.py index 315291e..777a111 100644 --- a/bootstrapvz/common/tools.py +++ b/bootstrapvz/common/tools.py @@ -1,3 +1,4 @@ +import os def log_check_call(command, stdin=None, env=None, shell=False, cwd=None): @@ -76,7 +77,6 @@ def load_yaml(path): def load_data(path): - import os.path filename, extension = os.path.splitext(path) if not os.path.isfile(path): raise Exception('The path {path} does not point to a file.'.format(path=path)) @@ -95,9 +95,17 @@ def config_get(path, config_path): return config +def get_codename(release): + """Normalizes the release codenames + This allows tasks to query for release codenames rather than 'stable', 'unstable' etc. + """ + release_codenames_path = os.path.join(os.path.dirname(__file__), 'release-codenames.yml') + from bootstrapvz.common.tools import config_get + return config_get(release_codenames_path, [release]) + + def copy_tree(from_path, to_path): from shutil import copy - import os for abs_prefix, dirs, files in os.walk(from_path): prefix = os.path.normpath(os.path.relpath(abs_prefix, from_path)) for path in dirs: diff --git a/bootstrapvz/plugins/cloud_init/__init__.py b/bootstrapvz/plugins/cloud_init/__init__.py index 999572b..0268d61 100644 --- a/bootstrapvz/plugins/cloud_init/__init__.py +++ b/bootstrapvz/plugins/cloud_init/__init__.py @@ -12,7 +12,8 @@ def resolve_tasks(taskset, manifest): from bootstrapvz.common.tasks import initd from bootstrapvz.common.tasks import ssh - if manifest.system['release'] in ['wheezy', 'stable']: + from bootstrapvz.common.tools import get_codename + if get_codename(manifest.system['release']) == 'wheezy': taskset.add(tasks.AddBackports) taskset.update([tasks.SetMetadataSource, diff --git a/bootstrapvz/plugins/cloud_init/tasks.py b/bootstrapvz/plugins/cloud_init/tasks.py index 44e2dff..6f64c38 100644 --- a/bootstrapvz/plugins/cloud_init/tasks.py +++ b/bootstrapvz/plugins/cloud_init/tasks.py @@ -29,7 +29,7 @@ class AddCloudInitPackages(Task): @classmethod def run(cls, info): target = None - if info.manifest.system['release'] in ['wheezy', 'stable']: + if info.release_codename == 'wheezy': target = '{system.release}-backports' info.packages.add('cloud-init', target) info.packages.add('sudo') diff --git a/bootstrapvz/plugins/docker_daemon/__init__.py b/bootstrapvz/plugins/docker_daemon/__init__.py index f2eda61..b85e32f 100644 --- a/bootstrapvz/plugins/docker_daemon/__init__.py +++ b/bootstrapvz/plugins/docker_daemon/__init__.py @@ -5,7 +5,8 @@ import os.path def validate_manifest(data, validator, error): schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml')) validator(data, schema_path) - if data.get('system', {}).get('release', None) in ['wheezy', 'stable']: + from bootstrapvz.common.tools import get_codename + if get_codename(data['system']['release']) == 'wheezy': # prefs is a generator of apt preferences across files in the manifest prefs = (item for vals in data.get('packages', {}).get('preferences', {}).values() for item in vals) if not any('linux-image' in item['package'] and 'wheezy-backports' in item['pin'] for item in prefs): diff --git a/bootstrapvz/plugins/opennebula/__init__.py b/bootstrapvz/plugins/opennebula/__init__.py index 4ac6056..bb90773 100644 --- a/bootstrapvz/plugins/opennebula/__init__.py +++ b/bootstrapvz/plugins/opennebula/__init__.py @@ -2,6 +2,7 @@ import tasks def resolve_tasks(taskset, manifest): - if manifest.system['release'] in ['wheezy', 'stable']: + from bootstrapvz.common.tools import get_codename + if get_codename(manifest.system['release']) == 'wheezy': taskset.add(tasks.AddBackports) taskset.update([tasks.AddONEContextPackage]) diff --git a/bootstrapvz/plugins/opennebula/tasks.py b/bootstrapvz/plugins/opennebula/tasks.py index 410bc90..4e5c48b 100644 --- a/bootstrapvz/plugins/opennebula/tasks.py +++ b/bootstrapvz/plugins/opennebula/tasks.py @@ -26,6 +26,6 @@ class AddONEContextPackage(Task): @classmethod def run(cls, info): target = None - if info.manifest.system['release'] in ['wheezy', 'stable']: + if info.release_codename == 'wheezy': target = '{system.release}-backports' info.packages.add('opennebula-context', target)