Revision 9cbb5794

b/image_creator/main.py
65 65
    parser.add_option("-f", "--force", dest="force", default=False,
66 66
        action="store_true", help="Overwrite output files if they exist")
67 67

  
68
    parser.add_option("--no-shrink", dest="shrink", default=True,
69
        help="Don't shrink any partition before extracting the image",
70
        action="store_false")
71

  
72 68
    parser.add_option("--no-cleanup", dest="cleanup", default=True,
73 69
        help="Don't cleanup sensitive data before extracting the image",
74 70
        action="store_false")
75 71

  
72
    parser.add_option("--no-sysprep", dest="sysprep", default=True,
73
        help="Don't perform system preperation before extracting the image",
74
        action="store_false")
75

  
76
    parser.add_option("--no-shrink", dest="shrink", default=True,
77
        help="Don't shrink any partition before extracting the image",
78
        action="store_false")
79

  
76 80
    parser.add_option("-u", "--upload", dest="upload", default=False,
77 81
        help="Upload image to a pithos repository using kamaki",
78 82
        action="store_true")
......
118 122
        osclass = get_os_class(dev.distro, dev.ostype)
119 123
        image_os = osclass(dev.root, dev.g)
120 124
        metadata = image_os.get_metadata()
125

  
126
        if options.sysprep:
127
            image_os.sysprep()
121 128
        
122 129
        if options.cleanup:
123 130
            image_os.data_cleanup()
b/image_creator/os_type/__init__.py
82 82
        """Cleanup sensitive data out of the OS image."""
83 83
        raise NotImplementedError
84 84

  
85
    def sysprep(self):
86
        """Prepere system for image creation."""
87
        raise NotImplementedError
88

  
85 89
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
b/image_creator/os_type/linux.py
20 20
                self._uuid[dev] = attr[1]
21 21
                return attr[1]
22 22

  
23
    def remove_persistent_net(self):
24
        persistent_net_rule = '/etc/udev/rules.d/70-persistent-net.rules'
25
        if self.g.is_file(persistent_net_rule):
26
            self.g.rm(persistent_net_rule)
27

  
28
    def convert_to_persistent_dev(self):
23
    def sysprep(self):
24
        """Prepere system for image creation."""
25
        self.sysprep_acpid()
26
        self.sysprep_persistent_net_rules()
27
        self.sysprep_persistent_devs()
28

  
29
    def sysprep_acpid(self):
30
        """Replace acpid powerdown action scripts to automatically shutdown
31
        the system without checking if a GUI is running.
32
        """
33
        action = '#!/bin/sh\n\nPATH=/sbin:/bin:/usr/bin\n shutdown -h now '
34
        '\"Power button pressed\"'
35

  
36
        if self.g.is_file('/etc/acpi/powerbtn.sh'):
37
            self.g.write(action, '/etc/acpi/powerbtn.sh')
38
        elif self.g.is_file('/etc/acpi/actions/power.sh'):
39
            self.g.write(actions, '/etc/acpi/actions/power.sh')
40
        else:
41
            print "Warning: No acpid action file found"
42

  
43
    def sysprep_persistent_net_rules(self):
44
        """Remove udev rules that will keep network interface names persistent
45
        after hardware changes and reboots. Those rules will be created again
46
        the next time the image runs.
47
        """
48
        rule_file = '/etc/udev/rules.d/70-persistent-net.rules'
49
        if self.g.is_file(rule_file):
50
            self.g.rm(rule_file)
51

  
52
    def sysprep_persistent_devs(self):
53
        """Scan fstab and grub configuration files and replace all
54
        non-persistent device appearences with UUIDs.
55
        """
29 56
        # convert all devices in fstab to persistent
30 57
        persistent_root = self._persistent_fstab()
31 58

  
32 59
        # convert all devices in grub1 to persistent
33 60
        self._persistent_grub1(persistent_root)
34 61

  
35
    def _persistent_grub1(self, conf, new_root):
62
    def _persistent_grub1(self, new_root):
36 63
        if self.g.is_file('/boot/grub/menu.lst'):
37 64
            grub1 = '/boot/grub/menu.lst'
38 65
        elif self.g.is_file('/etc/grub.conf'):

Also available in: Unified diff