Commit 0144d7c7 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Add exclude_task decorator in os_type

This can be used to create a set of by default disabled data_cleanup
and sysprep tasks.
parent 979096dd
......@@ -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 :
......@@ -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):
......
......@@ -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):
......
......@@ -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.
"""
......
......@@ -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):
......
......@@ -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):
......
......@@ -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):
......
......@@ -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"""
......
......@@ -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):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment