commit 9cbb5794bf4c103861f7d9dd0bd800ff0ad7eaf7
Author: Nikos Skalkotos <skalkoto@grnet.gr>
Date:   Tue Mar 13 17:48:54 2012 +0200

    Add sysprep method in os_type classes.
    
    This is used to prepare the media for image extraction. The main
    difference from data_cleanup is that the tasks performed with this
    method are mandatory in order to make the image workable.
    
    Added the following sysprep methods for linux:
     * sysprep_acpid
     * sysprep_persistent_net_rules
     * sysprep_persistend_devs

diff --git a/image_creator/main.py b/image_creator/main.py
index 3b25bc5..c08906f 100644
--- a/image_creator/main.py
+++ b/image_creator/main.py
@@ -65,14 +65,18 @@ def parse_options(input_args):
     parser.add_option("-f", "--force", dest="force", default=False,
         action="store_true", help="Overwrite output files if they exist")
 
-    parser.add_option("--no-shrink", dest="shrink", default=True,
-        help="Don't shrink any partition before extracting the image",
-        action="store_false")
-
     parser.add_option("--no-cleanup", dest="cleanup", default=True,
         help="Don't cleanup sensitive data before extracting the image",
         action="store_false")
 
+    parser.add_option("--no-sysprep", dest="sysprep", default=True,
+        help="Don't perform system preperation before extracting the image",
+        action="store_false")
+
+    parser.add_option("--no-shrink", dest="shrink", default=True,
+        help="Don't shrink any partition before extracting the image",
+        action="store_false")
+
     parser.add_option("-u", "--upload", dest="upload", default=False,
         help="Upload image to a pithos repository using kamaki",
         action="store_true")
@@ -118,6 +122,9 @@ def main():
         osclass = get_os_class(dev.distro, dev.ostype)
         image_os = osclass(dev.root, dev.g)
         metadata = image_os.get_metadata()
+
+        if options.sysprep:
+            image_os.sysprep()
         
         if options.cleanup:
             image_os.data_cleanup()
diff --git a/image_creator/os_type/__init__.py b/image_creator/os_type/__init__.py
index 5fd00ab..c5e38eb 100644
--- a/image_creator/os_type/__init__.py
+++ b/image_creator/os_type/__init__.py
@@ -82,4 +82,8 @@ class OSBase(object):
         """Cleanup sensitive data out of the OS image."""
         raise NotImplementedError
 
+    def sysprep(self):
+        """Prepere system for image creation."""
+        raise NotImplementedError
+
 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
diff --git a/image_creator/os_type/linux.py b/image_creator/os_type/linux.py
index b6f8c8d..724e902 100644
--- a/image_creator/os_type/linux.py
+++ b/image_creator/os_type/linux.py
@@ -20,19 +20,46 @@ class Linux(Unix):
                 self._uuid[dev] = attr[1]
                 return attr[1]
 
-    def remove_persistent_net(self):
-        persistent_net_rule = '/etc/udev/rules.d/70-persistent-net.rules'
-        if self.g.is_file(persistent_net_rule):
-            self.g.rm(persistent_net_rule)
-
-    def convert_to_persistent_dev(self):
+    def sysprep(self):
+        """Prepere system for image creation."""
+        self.sysprep_acpid()
+        self.sysprep_persistent_net_rules()
+        self.sysprep_persistent_devs()
+
+    def sysprep_acpid(self):
+        """Replace acpid powerdown action scripts to automatically shutdown
+        the system without checking if a GUI is running.
+        """
+        action = '#!/bin/sh\n\nPATH=/sbin:/bin:/usr/bin\n shutdown -h now '
+        '\"Power button pressed\"'
+
+        if self.g.is_file('/etc/acpi/powerbtn.sh'):
+            self.g.write(action, '/etc/acpi/powerbtn.sh')
+        elif self.g.is_file('/etc/acpi/actions/power.sh'):
+            self.g.write(actions, '/etc/acpi/actions/power.sh')
+        else:
+            print "Warning: No acpid action file found"
+
+    def sysprep_persistent_net_rules(self):
+        """Remove udev rules that will keep network interface names persistent
+        after hardware changes and reboots. Those rules will be created again
+        the next time the image runs.
+        """
+        rule_file = '/etc/udev/rules.d/70-persistent-net.rules'
+        if self.g.is_file(rule_file):
+            self.g.rm(rule_file)
+
+    def sysprep_persistent_devs(self):
+        """Scan fstab and grub configuration files and replace all
+        non-persistent device appearences with UUIDs.
+        """
         # convert all devices in fstab to persistent
         persistent_root = self._persistent_fstab()
 
         # convert all devices in grub1 to persistent
         self._persistent_grub1(persistent_root)
 
-    def _persistent_grub1(self, conf, new_root):
+    def _persistent_grub1(self, new_root):
         if self.g.is_file('/boot/grub/menu.lst'):
             grub1 = '/boot/grub/menu.lst'
         elif self.g.is_file('/etc/grub.conf'):
