diff --git a/common/tasks/packages.py b/common/tasks/packages.py new file mode 100644 index 0000000..2d868d9 --- /dev/null +++ b/common/tasks/packages.py @@ -0,0 +1,27 @@ +from base import Task +from common import phases + + +class HostPackages(Task): + description = 'Determining required host packages' + phase = phases.preparation + + def run(self, info): + packages = set(['debootstrap']) + info.host_packages = packages + + +class ImagePackages(Task): + description = 'Determining required image packages' + phase = phases.preparation + + def run(self, info): + # Add some basic packages we are going to need + include = set(['udev', + 'openssh-server', + # We could bootstrap without locales, but things just suck without them, error messages etc. + 'locales', + ]) + exclude = set() + + info.img_packages = include, exclude diff --git a/plugins/admin_user/tasks.py b/plugins/admin_user/tasks.py index 96df75b..3df12f4 100644 --- a/plugins/admin_user/tasks.py +++ b/plugins/admin_user/tasks.py @@ -1,6 +1,6 @@ from base import Task from common import phases -from providers.ec2.tasks.packages import ImagePackages +from common.tasks.packages import ImagePackages from common.tasks.host import CheckPackages from common.tasks.initd import InstallInitScripts import os diff --git a/plugins/unattended_upgrades/tasks.py b/plugins/unattended_upgrades/tasks.py index b8b11de..b83f421 100644 --- a/plugins/unattended_upgrades/tasks.py +++ b/plugins/unattended_upgrades/tasks.py @@ -1,6 +1,6 @@ from base import Task from common import phases -from providers.ec2.tasks.packages import ImagePackages +from common.tasks.packages import ImagePackages from common.tasks.host import CheckPackages diff --git a/plugins/user_packages/user_packages.py b/plugins/user_packages/user_packages.py index e1093ca..82ab462 100644 --- a/plugins/user_packages/user_packages.py +++ b/plugins/user_packages/user_packages.py @@ -1,8 +1,8 @@ from base import Task from common import phases import os -from providers.raw.tasks.packages import ImagePackages -from providers.raw.tasks.host import CheckPackages +from common.tasks.packages import ImagePackages +from common.tasks.host import CheckPackages from providers.raw.tasks.filesystem import MountVolume @@ -18,28 +18,28 @@ class AddUserPackages(Task): for pkg in info.manifest.plugins['user_packages']['repo']: info.img_packages[0].add(pkg) + class AddLocalUserPackages(Task): - description = 'Adding user local packages to the image packages' - phase = phases.system_modification - after = [MountVolume] + description = 'Adding user local packages to the image packages' + phase = phases.system_modification + after = [MountVolume] - def run(self, info): - if 'local' not in info.manifest.plugins['user_packages']: - return + def run(self, info): + if 'local' not in info.manifest.plugins['user_packages']: + return - import stat - rwxr_xr_x = (stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | - stat.S_IRGRP | stat.S_IXGRP | - stat.S_IROTH | stat.S_IXOTH) + import stat + rwxr_xr_x = (stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | + stat.S_IRGRP | stat.S_IXGRP | + stat.S_IROTH | stat.S_IXOTH) - from shutil import copy - from common.tools import log_check_call + from shutil import copy + from common.tools import log_check_call for pkg in info.manifest.plugins['user_packages']['local']: - script_src = os.path.normpath(pkg) - script_dst = os.path.join(info.root, 'tmp/'+os.path.basename(script_src)) - copy(script_src, script_dst) - os.chmod(script_dst, rwxr_xr_x) - - log_check_call(['/usr/sbin/chroot', info.root, 'dpkg', '-i', '/tmp/'+os.path.basename(script_src)]) + script_src = os.path.normpath(pkg) + script_dst = os.path.join(info.root, 'tmp/'+os.path.basename(script_src)) + copy(script_src, script_dst) + os.chmod(script_dst, rwxr_xr_x) + log_check_call(['/usr/sbin/chroot', info.root, 'dpkg', '-i', '/tmp/'+os.path.basename(script_src)]) diff --git a/providers/ec2/__init__.py b/providers/ec2/__init__.py index 34f3d7f..04be78b 100644 --- a/providers/ec2/__init__.py +++ b/providers/ec2/__init__.py @@ -1,6 +1,7 @@ from manifest import Manifest import logging from tasks import packages +from common.tasks import packages as common_packages from tasks import connection from tasks import host from common.tasks import host as common_host @@ -27,7 +28,9 @@ def initialize(): def tasks(tasklist, manifest): tasklist.add(packages.HostPackages(), + common_packages.HostPackages(), packages.ImagePackages(), + common_packages.ImagePackages(), common_host.CheckPackages(), connection.GetCredentials(), host.GetInfo(), diff --git a/providers/ec2/tasks/packages.py b/providers/ec2/tasks/packages.py index 9b8c739..a884b7f 100644 --- a/providers/ec2/tasks/packages.py +++ b/providers/ec2/tasks/packages.py @@ -1,44 +1,37 @@ from base import Task from common import phases +from common.tasks import packages +from common.tasks.host import CheckPackages class HostPackages(Task): - description = 'Determining required host packages' + description = 'Adding more required host packages' phase = phases.preparation + before = [CheckPackages] + after = [packages.HostPackages] def run(self, info): - packages = set(['debootstrap']) if info.manifest.volume['filesystem'] == 'xfs': - packages.add('xfsprogs') + info.host_packages.add('xfsprogs') if info.manifest.volume['backing'] == 's3': - packages.add('euca2ools') - - info.host_packages = packages + info.host_packages.add('euca2ools') class ImagePackages(Task): - description = 'Determining required image packages' + description = 'Adding more required image packages' phase = phases.preparation + after = [packages.ImagePackages] def run(self, info): manifest = info.manifest - # Add some basic packages we are going to need - include = set(['udev', - 'openssh-server', - # We could bootstrap without locales, but things just suck without them, error messages etc. - 'locales', - # Needed for the init scripts - 'file', - # isc-dhcp-client doesn't work properly with ec2 - 'dhcpcd', - ]) - + include, exclude = info.img_packages + include.add('file') # Needed for the init scripts + include.add('dhcpcd') # isc-dhcp-client doesn't work properly with ec2 if manifest.virtualization == 'pvm': include.add('grub-pc') - exclude = set(['isc-dhcp-client', - 'isc-dhcp-common', - ]) + exclude.add('isc-dhcp-client') + exclude.add('isc-dhcp-common') # In squeeze, we need a special kernel flavor for xen kernels = {'squeeze': {'amd64': 'linux-image-xen-amd64', @@ -46,5 +39,3 @@ class ImagePackages(Task): 'wheezy': {'amd64': 'linux-image-amd64', 'i386': 'linux-image-686', }, } include.add(kernels.get(manifest.system['release']).get(manifest.system['architecture'])) - - info.img_packages = include, exclude diff --git a/providers/one/__init__.py b/providers/one/__init__.py index d46dede..49eec72 100644 --- a/providers/one/__init__.py +++ b/providers/one/__init__.py @@ -1,5 +1,6 @@ from manifest import Manifest from tasks import packages +from common.tasks import packages as common_packages from tasks import host from tasks import filesystem from common.tasks import filesystem as common_filesystem @@ -21,7 +22,9 @@ def initialize(): def tasks(tasklist, manifest): tasklist.add(packages.HostPackages(), + common_packages.HostPackages(), packages.ImagePackages(), + common_packages.ImagePackages(), host.CheckPackages(), filesystem.FormatVolume(), diff --git a/providers/one/tasks/packages.py b/providers/one/tasks/packages.py index cb098ca..c7fcfe5 100644 --- a/providers/one/tasks/packages.py +++ b/providers/one/tasks/packages.py @@ -1,31 +1,31 @@ from base import Task from common import phases +from common.tasks import packages +from common.tasks.host import CheckPackages class HostPackages(Task): description = 'Determining required host packages' phase = phases.preparation + before = [CheckPackages] + after = [packages.HostPackages] def run(self, info): - packages = set(['debootstrap', 'qemu-utils', 'parted', 'grub2', 'sysv-rc']) + info.host_packages.update(['qemu-utils', 'parted', 'grub2', 'sysv-rc']) if info.manifest.volume['filesystem'] == 'xfs': - packages.add('xfsprogs') - - info.host_packages = packages + info.host_packages.add('xfsprogs') class ImagePackages(Task): description = 'Determining required image packages' phase = phases.preparation + after = [packages.ImagePackages] def run(self, info): manifest = info.manifest + include, exclude = info.img_packages # Add some basic packages we are going to need - include = set(['udev', - 'parted', - 'openssh-server', - # We could bootstrap without locales, but things just suck without them, error messages etc. - 'locales', + include.update(['parted', # Needed for the init scripts 'file', # isc-dhcp-client doesn't work properly with ec2 @@ -33,11 +33,11 @@ class ImagePackages(Task): 'grub2', 'chkconfig', 'openssh-client' - ]) + ]) - exclude = set(['isc-dhcp-client', + exclude.update(['isc-dhcp-client', 'isc-dhcp-common', - ]) + ]) # In squeeze, we need a special kernel flavor for xen kernels = {'squeeze': {'amd64': 'linux-image-amd64', @@ -45,5 +45,3 @@ class ImagePackages(Task): 'wheezy': {'amd64': 'linux-image-amd64', 'i386': 'linux-image-686', }, } include.add(kernels.get(manifest.system['release']).get(manifest.system['architecture'])) - - info.img_packages = include, exclude