~ubuntu-virt/vmbuilder/trunk

« back to all changes in this revision

Viewing changes to VMBuilder/plugins/ubuntu/suite.py

  • Committer: Soren Hansen
  • Date: 2008-06-27 12:47:26 UTC
  • Revision ID: soren.hansen@canonical.com-20080627124726-kj690sepircudc3h
Import python rewrite.. It's not quite at a useful point yet (only cli+kvm+hardy is in a usable state), but it's getting there..

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from VMBuilder.util import run_cmd
 
2
import VMBuilder
 
3
import logging
 
4
import glob
 
5
 
 
6
class Suite(object):
 
7
    def __init__(self, builder):
 
8
        self.builder = builder
 
9
 
 
10
    def install(self, destdir):
 
11
        self.destdir = destdir
 
12
 
 
13
        logging.debug("debootstrapping")
 
14
        self.debootstrap()
 
15
 
 
16
        logging.debug("Installing fstab")
 
17
        self.install_fstab()
 
18
    
 
19
        logging.debug("Installing kernel")
 
20
        self.install_kernel()
 
21
 
 
22
        logging.debug("Installing grub")
 
23
        self.install_grub()
 
24
 
 
25
        logging.debug("Creating device.map")
 
26
        self.install_device_map()
 
27
 
 
28
        logging.debug("Installing menu.list")
 
29
        self.install_menu_lst()
 
30
 
 
31
        logging.debug("Unmounting volatile lrm filesystems")
 
32
        self.unmount_volatile()
 
33
 
 
34
    def unmount_volatile(self):
 
35
        for mntpnt in glob.glob('%s/lib/modules/*/volatile' % self.destdir):
 
36
            logging.debug("Unmounting %s" % mntpnt)
 
37
            run_cmd('umount', mntpnt)
 
38
 
 
39
    def install_menu_lst(self):
 
40
        run_cmd('chroot', self.destdir, 'update-grub', '-y')
 
41
        self.mangle_grub_menu_lst()
 
42
        run_cmd('chroot', self.destdir, 'update-grub')
 
43
 
 
44
    def mangle_grub_menu_lst(self):
 
45
        bootdev = 'UUID=%s' % (VMBuilder.bootpart().uuid, )
 
46
        run_cmd('sed', '-ie', 's/\/dev\/hda1/%s/g' % bootdev, '%s/boot/grub/menu.lst' % self.destdir)
 
47
 
 
48
    def install_fstab(self):
 
49
        fp = open('%s/etc/fstab' % self.destdir, 'w')
 
50
        fp.write(self.fstab())
 
51
        fp.close()
 
52
 
 
53
    def install_device_map(self):
 
54
        fp = open('%s/boot/grub/device.map' % self.destdir, 'a')
 
55
        fp.write(self.device_map())
 
56
        fp.close()
 
57
 
 
58
    def device_map(self):
 
59
        raise NotImplemented('Suite needs to implement device_map method')
 
60
 
 
61
    def debootstrap(self):
 
62
        cmd = ['debootstrap', self.builder.options.suite, self.destdir]
 
63
        if hasattr(self.builder.options, 'mirror'):
 
64
            cmd += [self.builder.options.mirror]
 
65
        run_cmd(*cmd)
 
66
 
 
67
    def install_kernel(self):
 
68
        kernel_name = self.kernel_name()
 
69
        run_cmd('chroot', self.destdir, 'apt-get', '--force-yes', '-y', 'install', kernel_name, 'grub')
 
70
 
 
71
    def install_grub(self):
 
72
        run_cmd('chroot', self.destdir, 'apt-get', '--force-yes', '-y', 'install', 'grub')
 
73
        run_cmd('cp', '-a', '%s%s' % (self.destdir, self.grubdir()), '%s/boot/grub' % self.destdir) 
 
74
 
 
75
    def grubdir(self):
 
76
        if self.builder.options.arch == 'amd64':
 
77
            return '/usr/lib/grub/x86_64-pc'
 
78
        else:
 
79
            return '/usr/lib/grub/i386-pc'
 
80
 
 
81
    def kernel_name(self):
 
82
        raise NotImplemented('Suite needs to implement kernel_name method')
 
83
 
 
84
    def fstab(self):
 
85
        retval = '''# /etc/fstab: static file system information.
 
86
#
 
87
# <file system>                                 <mount point>   <type>  <options>       <dump>  <pass>
 
88
proc                                            /proc           proc    defaults        0       0
 
89
'''
 
90
        parts = self.builder.get_ordered_partitions()
 
91
        for part in parts:
 
92
            retval += "UUID=%-40s %15s %7s %15s %d       %d\n" % (part.uuid, part.mntpnt, part.fstab_fstype(), part.fstab_options(), 0, 0)
 
93
        return retval
 
94
 
 
95