From: Nikos Skalkotos Date: Thu, 5 Apr 2012 13:26:02 +0000 (+0300) Subject: Add exclude_task decorator in os_type X-Git-Tag: v0.1~117 X-Git-Url: https://code.grnet.gr/git/snf-image-creator/commitdiff_plain/0144d7c741cb742f52ef8755fc315afaa7ea4747 Add exclude_task decorator in os_type This can be used to create a set of by default disabled data_cleanup and sysprep tasks. --- diff --git a/image_creator/os_type/__init__.py b/image_creator/os_type/__init__.py index 17ca22e..03ca4a7 100644 --- a/image_creator/os_type/__init__.py +++ b/image_creator/os_type/__init__.py @@ -42,6 +42,9 @@ def add_prefix(target): return map(lambda x: prefix + x, target(self, *args)) return wrapper +def exclude_task(func): + func.excluded = True + return func class OSBase(object): """Basic operating system class""" @@ -116,9 +119,7 @@ class OSBase(object): output('Cleaning up sensitive data out of the OS image:') - is_cleanup = lambda x: x.startswith('data_cleanup_') and \ - callable(getattr(self, x)) - tasks = [getattr(self, x) for x in dir(self) if is_cleanup(x)] + tasks, _ = self.list_data_cleanup() size = len(tasks) cnt = 0 for task in tasks: @@ -132,9 +133,7 @@ class OSBase(object): output('Preparing system for image creation:') - is_sysprep = lambda x: x.startswith('sysprep_') and \ - callable(getattr(self, x)) - tasks = [getattr(self, x) for x in dir(self) if is_sysprep(x)] + tasks, _ = self.list_sysprep() size = len(tasks) cnt = 0 for task in tasks: @@ -143,4 +142,28 @@ class OSBase(object): task() output() + def list_sysprep(self): + """List all sysprep actions""" + + is_sysprep = lambda x: x.startswith('sysprep_') and \ + callable(getattr(self, x)) + tasks = [getattr(self, x) for x in dir(self) if is_sysprep(x)] + + included = [t for t in tasks if not getattr(t, "excluded", False)] + excluded = [t for t in tasks if getattr(t, "excluded", False)] + + return included, excluded + + def list_data_cleanup(self): + """List all data_cleanup actions""" + + is_cleanup = lambda x: x.startswith('data_cleanup_') and \ + callable(getattr(self, x)) + tasks = [getattr(self, x) for x in dir(self) if is_cleanup(x)] + + included = [t for t in tasks if not getattr(t, "excluded", False)] + excluded = [t for t in tasks if getattr(t, "excluded", False)] + + return included, excluded + # vim: set sta sts=4 shiftwidth=4 sw=4 et ai : diff --git a/image_creator/os_type/freebsd.py b/image_creator/os_type/freebsd.py index 33ba887..c2e1a5c 100644 --- a/image_creator/os_type/freebsd.py +++ b/image_creator/os_type/freebsd.py @@ -31,7 +31,7 @@ # interpreted as representing official policies, either expressed # or implied, of GRNET S.A. -from image_creator.os_type.unix import Unix +from image_creator.os_type.unix import Unix, exclude_task class Freebsd(Unix): diff --git a/image_creator/os_type/hurd.py b/image_creator/os_type/hurd.py index 25264ab..bba3e65 100644 --- a/image_creator/os_type/hurd.py +++ b/image_creator/os_type/hurd.py @@ -31,7 +31,7 @@ # interpreted as representing official policies, either expressed # or implied, of GRNET S.A. -from image_creator.os_type.unix import Unix +from image_creator.os_type.unix import Unix, exclude_task class Hard(Unix): diff --git a/image_creator/os_type/linux.py b/image_creator/os_type/linux.py index 7a6fab1..31e651d 100644 --- a/image_creator/os_type/linux.py +++ b/image_creator/os_type/linux.py @@ -31,7 +31,7 @@ # interpreted as representing official policies, either expressed # or implied, of GRNET S.A. -from image_creator.os_type.unix import Unix +from image_creator.os_type.unix import Unix, exclude_task from image_creator.util import warn, output import re @@ -56,7 +56,7 @@ class Linux(Unix): self._uuid[dev] = attr[1] return attr[1] - def sysprep_acpid(self, print_header=True): + def sysprep_fix_acpid(self, print_header=True): """Replace acpid powerdown action scripts to immediately shutdown the system without checking if a GUI is running. """ diff --git a/image_creator/os_type/netbsd.py b/image_creator/os_type/netbsd.py index bfb94d6..9973b28 100644 --- a/image_creator/os_type/netbsd.py +++ b/image_creator/os_type/netbsd.py @@ -31,7 +31,7 @@ # interpreted as representing official policies, either expressed # or implied, of GRNET S.A. -from image_creator.os_type.unix import Unix +from image_creator.os_type.unix import Unix, exclude_task class Netbsd(Unix): diff --git a/image_creator/os_type/slackware.py b/image_creator/os_type/slackware.py index d4f4c44..ac7ded0 100644 --- a/image_creator/os_type/slackware.py +++ b/image_creator/os_type/slackware.py @@ -31,7 +31,7 @@ # interpreted as representing official policies, either expressed # or implied, of GRNET S.A. -from image_creator.os_type.linux import Linux +from image_creator.os_type.linux import Linux, exclude_task class Slackware(Linux): diff --git a/image_creator/os_type/ubuntu.py b/image_creator/os_type/ubuntu.py index 77d80ff..4dec1e8 100644 --- a/image_creator/os_type/ubuntu.py +++ b/image_creator/os_type/ubuntu.py @@ -31,7 +31,7 @@ # interpreted as representing official policies, either expressed # or implied, of GRNET S.A. -from image_creator.os_type.linux import Linux +from image_creator.os_type.linux import Linux, exclude_task class Ubuntu(Linux): diff --git a/image_creator/os_type/unix.py b/image_creator/os_type/unix.py index 75c4797..b5d0ba7 100644 --- a/image_creator/os_type/unix.py +++ b/image_creator/os_type/unix.py @@ -34,7 +34,7 @@ import re import sys -from image_creator.os_type import OSBase +from image_creator.os_type import OSBase, exclude_task from image_creator.util import warn, output @@ -95,6 +95,7 @@ class Unix(OSBase): self.foreach_file('/var/log', self.g.truncate, ftype='r') + @exclude_task def data_cleanup_mail(self, print_header=True): """Remove all files under /var/mail and /var/spool/mail""" diff --git a/image_creator/os_type/windows.py b/image_creator/os_type/windows.py index 7ba6767..036e33b 100644 --- a/image_creator/os_type/windows.py +++ b/image_creator/os_type/windows.py @@ -31,7 +31,7 @@ # interpreted as representing official policies, either expressed # or implied, of GRNET S.A. -from image_creator.os_type import OSBase +from image_creator.os_type import OSBase, exclude_task class Windows(OSBase):