~ubuntu-branches/ubuntu/precise/vm-builder/precise

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Soren Hansen
  • Date: 2010-02-22 13:56:18 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20100222135618-la13e3mu397rg0m1
Tags: 0.12.0-0ubuntu1
* New upstream release. (FFe: LP: #525741)
  - All patches incorporated upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#
2
2
#    Uncomplicated VM Builder
3
 
#    Copyright (C) 2007-2009 Canonical Ltd.
4
 
#    
 
3
#    Copyright (C) 2007-2010 Canonical Ltd.
 
4
#
5
5
#    See AUTHORS for list of contributors
6
6
#
7
7
#    This program is free software: you can redistribute it and/or modify
25
25
import tempfile
26
26
import VMBuilder
27
27
import VMBuilder.disk as disk
28
 
from   VMBuilder.util import run_cmd
 
28
from   VMBuilder.util import run_cmd #, give_to_caller
29
29
 
30
30
class Dapper(suite.Suite):
31
31
    updategrub = "/sbin/update-grub"
37
37
    xen_kernel_flavour = None
38
38
    virtio_net = False
39
39
    chpasswd_cmd = [ 'chpasswd', '--md5' ]
 
40
    preferred_filesystem = 'ext2'
40
41
 
41
42
    def pre_install(self):
42
43
        pass
48
49
        return arch in self.valid_flavours.keys()
49
50
        
50
51
    def install(self, destdir):
51
 
        self.destdir = destdir
52
 
 
53
 
        logging.debug("debootstrapping")
54
 
        self.debootstrap()
55
 
 
56
 
        self.pre_install()
57
 
 
58
 
        logging.debug("Setting up sources.list")
59
 
        self.install_sources_list()
60
 
 
61
 
        logging.debug("Setting up apt proxy")
62
 
        self.install_apt_proxy()
63
 
 
64
 
        logging.debug("Installing fstab")
65
 
        self.install_fstab()
66
 
 
67
 
        logging.debug("Creating devices")
68
 
        self.create_devices()
69
 
    
70
 
        if self.vm.hypervisor.needs_bootloader:
71
 
            logging.debug("Installing grub")
72
 
            self.install_grub()
73
 
        
74
 
        logging.debug("Configuring guest networking")
75
 
        self.config_network()
76
 
 
77
 
        logging.debug("Preventing daemons from starting")
78
 
        self.prevent_daemons_starting()
79
 
 
80
 
        logging.debug('Binding /dev and /proc filesystems')
81
 
        self.mount_dev_proc()
82
 
 
83
 
        if self.vm.hypervisor.needs_bootloader:
84
 
            logging.debug("Installing menu.list")
85
 
            self.install_menu_lst()
86
 
 
87
 
            logging.debug("Installing kernel")
88
 
            self.install_kernel()
89
 
 
90
 
            logging.debug("Creating device.map")
91
 
            self.install_device_map()
92
 
 
93
 
        logging.debug("Installing extra packages")
94
 
        self.install_extras()
95
 
 
96
 
        logging.debug("Creating initial user")
97
 
        self.create_initial_user()
98
 
 
99
 
        logging.debug("Installing ssh keys")
100
 
        self.install_authorized_keys()
 
52
        raise VMBuilderException('Do not call this method!')
 
53
 
 
54
        # These are still missing after the refactoring.
 
55
        logging.debug("Creating device.map")
 
56
        self.install_device_map()
101
57
 
102
58
        logging.debug("Copy host settings")
103
59
        self.copy_settings()
105
61
        logging.debug("Setting timezone")
106
62
        self.set_timezone()
107
63
 
108
 
        logging.debug("Making sure system is up-to-date")
109
 
        self.update()
110
 
 
111
 
        logging.debug("Setting up final sources.list")
112
 
        self.install_sources_list(final=True)
113
 
 
114
 
        logging.debug("cleaning apt")
115
 
        self.run_in_target('apt-get', 'clean');
116
 
 
117
 
        logging.debug("Unmounting volatile lrm filesystems")
118
 
        self.unmount_volatile()
119
 
 
120
 
        logging.debug('Unbinding /dev and /proc filesystems')
121
 
        self.unmount_dev_proc()
122
 
 
123
 
        if hasattr(self.vm, 'ec2') and self.vm.ec2:
 
64
        if hasattr(self.context, 'ec2') and self.context.ec2:
124
65
            logging.debug("Configuring for ec2")
125
66
            self.install_ec2()
126
67
 
127
 
        logging.debug("Unpreventing daemons from starting")
128
 
        self.unprevent_daemons_starting()
129
 
 
130
 
        if self.vm.manifest:
 
68
    def create_manifest(self):
 
69
        manifest = self.context.get_setting('manifest')
 
70
        if manifest:
131
71
            logging.debug("Creating manifest")
132
72
            manifest_contents = self.run_in_target('dpkg-query', '-W', '--showformat=${Package} ${Version}\n')
133
 
            fp = open(self.vm.manifest, 'w')
 
73
            fp = open(manifest, 'w')
134
74
            fp.write(manifest_contents)
135
75
            fp.close
 
76
            self.call_hook('fix_ownership', manifest)
136
77
 
137
78
    def update(self):
138
79
        self.run_in_target('apt-get', '-y', '--force-yes', 'dist-upgrade',
139
80
                           env={ 'DEBIAN_FRONTEND' : 'noninteractive' })
140
81
        
141
82
    def install_authorized_keys(self):
142
 
        if self.vm.ssh_key:
143
 
            os.mkdir('%s/root/.ssh' % self.destdir, 0700)
144
 
            shutil.copy(self.vm.ssh_key, '%s/root/.ssh/authorized_keys' % self.destdir)
145
 
            os.chmod('%s/root/.ssh/authorized_keys' % self.destdir, 0644)
146
 
        if self.vm.ssh_user_key:
147
 
            os.mkdir('%s/home/%s/.ssh' % (self.destdir, self.vm.user), 0700)
148
 
            shutil.copy(self.vm.ssh_user_key, '%s/home/%s/.ssh/authorized_keys' % (self.destdir, self.vm.user))
149
 
            os.chmod('%s/home/%s/.ssh/authorized_keys' % (self.destdir, self.vm.user), 0644)
150
 
            self.run_in_target('chown', '-R', '%s:%s' % (self.vm.user,)*2, '/home/%s/.ssh/' % (self.vm.user)) 
151
 
 
152
 
        if self.vm.ssh_user_key or self.vm.ssh_key:
153
 
            if not self.vm.addpkg:
154
 
                self.vm.addpkg = []
155
 
            self.vm.addpkg += ['openssh-server']
 
83
        ssh_key = self.context.get_setting('ssh-key')
 
84
        if ssh_key:
 
85
            os.mkdir('%s/root/.ssh' % self.context.chroot_dir, 0700)
 
86
            shutil.copy(ssh_key, '%s/root/.ssh/authorized_keys' % self.context.chroot_dir)
 
87
            os.chmod('%s/root/.ssh/authorized_keys' % self.context.chroot_dir, 0644)
 
88
 
 
89
        user = self.context.get_setting('user')
 
90
        ssh_user_key = self.context.get_setting('ssh-user-key')
 
91
        if ssh_user_key:
 
92
            os.mkdir('%s/home/%s/.ssh' % (self.context.chroot_dir, user), 0700)
 
93
            shutil.copy(ssh_user_key, '%s/home/%s/.ssh/authorized_keys' % (self.context.chroot_dir, user))
 
94
            os.chmod('%s/home/%s/.ssh/authorized_keys' % (self.context.chroot_dir, user), 0644)
 
95
            self.run_in_target('chown', '-R', '%s:%s' % ((user,)*2), '/home/%s/.ssh/' % (user)) 
 
96
 
 
97
        if ssh_user_key or ssh_key:
 
98
            addpkg = self.context.get_setting('addpkg')
 
99
            addpkg += ['openssh-server']
 
100
            self.context.set_setting('addpkg', addpkg)
156
101
 
157
102
    def mount_dev_proc(self):
158
 
        run_cmd('mount', '--bind', '/dev', '%s/dev' % self.destdir)
159
 
        self.vm.add_clean_cmd('umount', '%s/dev' % self.destdir, ignore_fail=True)
 
103
        run_cmd('mount', '--bind', '/dev', '%s/dev' % self.context.chroot_dir)
 
104
        self.context.add_clean_cb(self.unmount_dev)
160
105
 
161
 
        run_cmd('mount', '--bind', '/dev/pts', '%s/dev/pts' % self.destdir)
162
 
        self.vm.add_clean_cmd('umount', '%s/dev/pts' % self.destdir, ignore_fail=True)
 
106
        run_cmd('mount', '--bind', '/dev/pts', '%s/dev/pts' % self.context.chroot_dir)
 
107
        self.context.add_clean_cb(self.unmount_dev_pts)
163
108
 
164
109
        self.run_in_target('mount', '-t', 'proc', 'proc', '/proc')
165
 
        self.vm.add_clean_cmd('umount', '%s/proc' % self.destdir, ignore_fail=True)
166
 
 
167
 
    def unmount_dev_proc(self):
168
 
        run_cmd('umount', '%s/dev/pts' % self.destdir)
169
 
        run_cmd('umount', '%s/dev' % self.destdir)
170
 
        run_cmd('umount', '%s/proc' % self.destdir)
 
110
        self.context.add_clean_cb(self.unmount_proc)
 
111
 
 
112
    def unmount_proc(self):
 
113
        self.context.cancel_cleanup(self.unmount_proc)
 
114
        run_cmd('umount', '%s/proc' % self.context.chroot_dir)
 
115
 
 
116
    def unmount_dev_pts(self):
 
117
        self.context.cancel_cleanup(self.unmount_dev_pts)
 
118
        run_cmd('umount', '%s/dev/pts' % self.context.chroot_dir)
 
119
 
 
120
    def unmount_dev(self):
 
121
        self.context.cancel_cleanup(self.unmount_dev)
 
122
        run_cmd('umount', '%s/dev' % self.context.chroot_dir)
171
123
 
172
124
    def update_passwords(self):
173
125
        # Set the user password, using md5
174
 
        self.run_in_target(stdin=('%s:%s\n' % (self.vm.user, getattr(self.vm, 'pass'))), *self.chpasswd_cmd)
 
126
        user   = self.context.get_setting('user')
 
127
        passwd = self.context.get_setting('pass')
 
128
        self.run_in_target(stdin=('%s:%s\n' % (user, passwd)), *self.chpasswd_cmd)
175
129
 
176
130
        # Lock root account only if we didn't set the root password
177
 
        if self.vm.rootpass:
178
 
            self.run_in_target(stdin=('%s:%s\n' % ('root', self.vm.rootpass)), *self.chpasswd_cmd)
 
131
        rootpass = self.context.get_setting('rootpass')
 
132
        if rootpass:
 
133
            self.run_in_target(stdin=('%s:%s\n' % ('root', rootpass)), *self.chpasswd_cmd)
179
134
        else:
180
135
            self.run_in_target('usermod', '-L', 'root')
181
136
 
182
 
        if self.vm.lock_user:
183
 
            logging.info('Locking %s' %(self.vm.user))
184
 
            self.run_in_target('usermod', '-L', self.vm.user)
 
137
        lock_user = self.context.get_setting('lock-user')
 
138
        if lock_user:
 
139
            logging.info('Locking %s' % (user, ))
 
140
            self.run_in_target('usermod', '-L', user)
185
141
 
186
142
    def create_initial_user(self):
187
 
        if self.vm.uid:
188
 
            self.run_in_target('adduser', '--disabled-password', '--uid', self.vm.uid, '--gecos', self.vm.name, self.vm.user)
 
143
        uid  = self.context.get_setting('uid')
 
144
        name = self.context.get_setting('name')
 
145
        user = self.context.get_setting('user')
 
146
        if uid:
 
147
            self.run_in_target('adduser', '--disabled-password', '--uid', uid, '--gecos', name, user)
189
148
        else:
190
 
            self.run_in_target('adduser', '--disabled-password', '--gecos', self.vm.name, self.vm.user)
 
149
            self.run_in_target('adduser', '--disabled-password', '--gecos', name, user)
 
150
 
191
151
        self.run_in_target('addgroup', '--system', 'admin')
192
 
        self.run_in_target('adduser', self.vm.user, 'admin')
 
152
        self.run_in_target('adduser', user, 'admin')
193
153
 
194
154
        self.install_from_template('/etc/sudoers', 'sudoers')
195
155
        for group in ['adm', 'audio', 'cdrom', 'dialout', 'floppy', 'video', 'plugdev', 'dip', 'netdev', 'powerdev', 'lpadmin', 'scanner']:
196
 
            self.run_in_target('adduser', self.vm.user, group, ignore_fail=True)
 
156
            self.run_in_target('adduser', user, group, ignore_fail=True)
197
157
 
198
158
        self.update_passwords()
199
159
 
200
160
    def kernel_name(self):
201
 
        return 'linux-image-%s' % (self.vm.flavour or self.default_flavour[self.vm.arch],)
202
 
 
203
 
    def config_network(self):
204
 
        self.vm.install_file('/etc/hostname', self.vm.hostname)
205
 
        self.install_from_template('/etc/hosts', 'etc_hosts', { 'hostname' : self.vm.hostname, 'domain' : self.vm.domain }) 
206
 
        self.install_from_template('/etc/network/interfaces', 'interfaces')
 
161
        flavour = self.context.get_setting('flavour')
 
162
        arch = self.context.get_setting('arch')
 
163
        return 'linux-image-%s' % (flavour or self.default_flavour[arch],)
 
164
 
 
165
    def config_host_and_domainname(self):
 
166
        hostname = self.context.get_setting('hostname')
 
167
        domain = self.context.get_setting('domain')
 
168
        self.context.install_file('/etc/hostname', hostname)
 
169
        self.install_from_template('/etc/hosts', 'etc_hosts', { 'hostname' : hostname, 'domain' : domain }) 
 
170
 
 
171
    def config_interfaces(self, nics):
 
172
        self.install_from_template('/etc/network/interfaces', 'interfaces', { 'ip' : nics[0].type == 'dhcp' and 'dhcp' or nics[0].ip })
207
173
 
208
174
    def unprevent_daemons_starting(self):
209
 
        os.unlink('%s/usr/sbin/policy-rc.d' % self.destdir)
 
175
        os.unlink('%s/usr/sbin/policy-rc.d' % self.context.chroot_dir)
210
176
 
211
177
    def prevent_daemons_starting(self):
212
178
        os.chmod(self.install_from_template('/usr/sbin/policy-rc.d', 'nostart-policy-rc.d'), 0755)
213
179
 
214
180
    def install_extras(self):
215
 
        if not self.vm.addpkg and not self.vm.removepkg:
 
181
        addpkg = self.context.get_setting('addpkg')
 
182
        removepkg = self.context.get_setting('removepkg')
 
183
        if not addpkg and not removepkg:
216
184
            return
217
185
        cmd = ['apt-get', 'install', '-y', '--force-yes']
218
 
        cmd += self.vm.addpkg or []
219
 
        cmd += ['%s-' % pkg for pkg in self.vm.removepkg or []]
 
186
        cmd += addpkg or []
 
187
        cmd += ['%s-' % pkg for pkg in removepkg or []]
220
188
        self.run_in_target(env={ 'DEBIAN_FRONTEND' : 'noninteractive' }, *cmd)
221
189
        
222
190
    def unmount_volatile(self):
223
 
        for mntpnt in glob.glob('%s/lib/modules/*/volatile' % self.destdir):
 
191
        for mntpnt in glob.glob('%s/lib/modules/*/volatile' % self.context.chroot_dir):
224
192
            logging.debug("Unmounting %s" % mntpnt)
225
193
            run_cmd('umount', mntpnt)
226
194
 
227
 
    def install_menu_lst(self):
 
195
    def install_menu_lst(self, disks):
228
196
        self.run_in_target(self.updategrub, '-y')
229
 
        self.mangle_grub_menu_lst()
 
197
        self.mangle_grub_menu_lst(disks)
230
198
        self.run_in_target(self.updategrub)
231
199
        self.run_in_target('grub-set-default', '0')
232
200
 
233
 
    def mangle_grub_menu_lst(self):
234
 
        bootdev = disk.bootpart(self.vm.disks)
235
 
        run_cmd('sed', '-ie', 's/^# kopt=root=\([^ ]*\)\(.*\)/# kopt=root=\/dev\/hd%s%d\\2/g' % (bootdev.disk.devletters(), bootdev.get_index()+1), '%s/boot/grub/menu.lst' % self.destdir)
236
 
        run_cmd('sed', '-ie', 's/^# groot.*/# groot %s/g' % bootdev.get_grub_id(), '%s/boot/grub/menu.lst' % self.destdir)
237
 
        run_cmd('sed', '-ie', '/^# kopt_2_6/ d', '%s/boot/grub/menu.lst' % self.destdir)
 
201
    def mangle_grub_menu_lst(self, disks):
 
202
        bootdev = disk.bootpart(disks)
 
203
        run_cmd('sed', '-ie', 's/^# kopt=root=\([^ ]*\)\(.*\)/# kopt=root=\/dev\/hd%s%d\\2/g' % (bootdev.disk.devletters(), bootdev.get_index()+1), '%s/boot/grub/menu.lst' % self.context.chroot_dir)
 
204
        run_cmd('sed', '-ie', 's/^# groot.*/# groot %s/g' % bootdev.get_grub_id(), '%s/boot/grub/menu.lst' % self.context.chroot_dir)
 
205
        run_cmd('sed', '-ie', '/^# kopt_2_6/ d', '%s/boot/grub/menu.lst' % self.context.chroot_dir)
238
206
 
239
207
    def install_sources_list(self, final=False):
240
208
        if final:
241
 
            mirror, updates_mirror, security_mirror = self.vm.mirror, self.vm.mirror, self.vm.security_mirror
 
209
            mirror = updates_mirror = self.context.get_setting('mirror')
 
210
            security_mirror = self.context.get_setting('security-mirror')
242
211
        else:
243
212
            mirror, updates_mirror, security_mirror = self.install_mirrors()
244
213
 
245
 
        self.install_from_template('/etc/apt/sources.list', 'sources.list', { 'mirror' : mirror, 'security_mirror' : security_mirror, 'updates_mirror' : updates_mirror })
 
214
        components = self.context.get_setting('components')
 
215
        ppa        = self.context.get_setting('ppa')
 
216
        suite      = self.context.get_setting('suite')
 
217
        self.install_from_template('/etc/apt/sources.list', 'sources.list', { 'mirror' : mirror,
 
218
                                                                              'security_mirror' : security_mirror,
 
219
                                                                              'updates_mirror' : updates_mirror,
 
220
                                                                              'components' : components,
 
221
                                                                              'ppa' : ppa,
 
222
                                                                              'suite' : suite })
246
223
 
247
224
        # If setting up the final mirror, allow apt-get update to fail
248
225
        # (since we might be on a complete different network than the
250
227
        self.run_in_target('apt-get', 'update', ignore_fail=final)
251
228
 
252
229
    def install_apt_proxy(self):
253
 
        if self.vm.proxy is not None:
254
 
            self.vm.install_file('/etc/apt/apt.conf', '// Proxy added by vmbuilder\nAcquire::http { Proxy "%s"; };' % self.vm.proxy)
 
230
        proxy = self.context.get_setting('proxy')
 
231
        if proxy is not None:
 
232
            self.context.install_file('/etc/apt/apt.conf', '// Proxy added by vmbuilder\nAcquire::http { Proxy "%s"; };' % proxy)
255
233
 
256
 
    def install_fstab(self):
257
 
        if self.vm.hypervisor.preferred_storage == VMBuilder.hypervisor.STORAGE_FS_IMAGE:
258
 
            self.install_from_template('/etc/fstab', 'dapper_fstab_fsimage', { 'fss' : disk.get_ordered_filesystems(self.vm), 'prefix' : self.disk_prefix })
259
 
        else:
260
 
            self.install_from_template('/etc/fstab', 'dapper_fstab', { 'parts' : disk.get_ordered_partitions(self.vm.disks), 'prefix' : self.disk_prefix })
 
234
    def install_fstab(self, disks, filesystems):
 
235
        self.install_from_template('/etc/fstab', 'dapper_fstab', { 'parts' : disk.get_ordered_partitions(disks), 'prefix' : self.disk_prefix })
261
236
 
262
237
    def install_device_map(self):
263
238
        self.install_from_template('/boot/grub/device.map', 'devicemap', { 'prefix' : self.disk_prefix })
264
239
 
265
240
    def debootstrap(self):
266
 
        cmd = ['/usr/sbin/debootstrap', '--arch=%s' % self.vm.arch]
267
 
        if self.vm.variant:
268
 
            cmd += ['--variant=%s' % self.vm.variant]
269
 
        cmd += [self.vm.suite, self.destdir, self.debootstrap_mirror()]
 
241
        arch = self.context.get_setting('arch')
 
242
        cmd = ['/usr/sbin/debootstrap', '--arch=%s' % arch]
 
243
 
 
244
        variant = self.context.get_setting('variant')
 
245
        if variant:
 
246
            cmd += ['--variant=%s' % variant]
 
247
 
 
248
        suite = self.context.get_setting('suite')
 
249
        cmd += [suite, self.context.chroot_dir, self.debootstrap_mirror()]
270
250
        kwargs = { 'env' : { 'DEBIAN_FRONTEND' : 'noninteractive' } }
271
 
        if self.vm.proxy:
272
 
            kwargs['env']['http_proxy'] = self.vm.proxy
 
251
 
 
252
        proxy = self.context.get_setting('proxy')
 
253
        if proxy:
 
254
            kwargs['env']['http_proxy'] = proxy
273
255
        run_cmd(*cmd, **kwargs)
274
256
    
275
257
    def debootstrap_mirror(self):
276
 
        if self.vm.iso:
 
258
        iso = self.context.get_setting('iso')
 
259
        if iso:
277
260
            isodir = tempfile.mkdtemp()
278
 
            self.vm.add_clean_cb(lambda:os.rmdir(isodir))
279
 
            run_cmd('mount', '-o', 'loop', '-t', 'iso9660', self.vm.iso, isodir)
280
 
            self.vm.add_clean_cmd('umount', isodir)
 
261
            self.context.add_clean_cb(lambda:os.rmdir(isodir))
 
262
            run_cmd('mount', '-o', 'loop', '-t', 'iso9660', iso, isodir)
 
263
            self.context.add_clean_cmd('umount', isodir)
281
264
            self.iso_mounted = True
282
265
 
283
266
            return 'file://%s' % isodir
286
269
 
287
270
 
288
271
    def install_mirrors(self):
289
 
        if self.vm.install_mirror:
290
 
            mirror = self.vm.install_mirror
291
 
        else:
292
 
            mirror = self.vm.mirror
293
 
 
294
 
        if self.vm.install_mirror:
295
 
            updates_mirror = self.vm.install_mirror
296
 
        else:
297
 
            updates_mirror = self.vm.mirror
298
 
 
299
 
        if self.vm.install_security_mirror:
300
 
            security_mirror = self.vm.install_security_mirror
301
 
        else:
302
 
            security_mirror = self.vm.security_mirror
 
272
        install_mirror = self.context.get_setting('install-mirror')
 
273
        if install_mirror:
 
274
            mirror = install_mirror
 
275
        else:
 
276
            mirror = self.context.get_setting('mirror')
 
277
 
 
278
        updates_mirror = mirror
 
279
 
 
280
        install_security_mirror = self.context.get_setting('install-security-mirror')
 
281
        if install_security_mirror:
 
282
            security_mirror = install_security_mirror
 
283
        else:
 
284
            security_mirror = self.context.get_setting('security-mirror')
303
285
 
304
286
        return (mirror, updates_mirror, security_mirror)
305
287
 
306
 
    def install_kernel(self):
 
288
    def install_kernel(self, destdir):
307
289
        self.install_from_template('/etc/kernel-img.conf', 'kernelimg', { 'updategrub' : self.updategrub }) 
308
 
        run_cmd('chroot', self.destdir, 'apt-get', '--force-yes', '-y', 'install', self.kernel_name(), 'grub')
 
290
        run_cmd('chroot', destdir, 'apt-get', '--force-yes', '-y', 'install', self.kernel_name(), 'grub')
309
291
 
310
 
    def install_grub(self):
 
292
    def install_grub(self, chroot_dir):
 
293
        arch = self.context.get_setting('arch')
311
294
        self.run_in_target('apt-get', '--force-yes', '-y', 'install', 'grub')
312
 
        run_cmd('rsync', '-a', '%s%s/%s/' % (self.destdir, self.grubroot, self.vm.arch == 'amd64' and 'x86_64-pc' or 'i386-pc'), '%s/boot/grub/' % self.destdir) 
 
295
        run_cmd('rsync', '-a', '%s%s/%s/' % (chroot_dir, self.grubroot, arch == 'amd64' and 'x86_64-pc' or 'i386-pc'), '%s/boot/grub/' % chroot_dir) 
313
296
 
314
297
    def create_devices(self):
315
 
        import VMBuilder.plugins.xen
 
298
        pass
 
299
# FIXME
 
300
#        import VMBuilder.plugins.xen
316
301
 
317
 
        if isinstance(self.vm.hypervisor, VMBuilder.plugins.xen.Xen):
318
 
            self.run_in_target('mknod', '/dev/xvda', 'b', '202', '0')
319
 
            self.run_in_target('mknod', '/dev/xvda1', 'b', '202', '1')
320
 
            self.run_in_target('mknod', '/dev/xvda2', 'b', '202', '2')
321
 
            self.run_in_target('mknod', '/dev/xvda3', 'b', '202', '3')
322
 
            self.run_in_target('mknod', '/dev/xvc0', 'c', '204', '191')
 
302
#        if isinstance(self.context.hypervisor, VMBuilder.plugins.xen.Xen):
 
303
#            self.run_in_target('mknod', '/dev/xvda', 'b', '202', '0')
 
304
#            self.run_in_target('mknod', '/dev/xvda1', 'b', '202', '1')
 
305
#            self.run_in_target('mknod', '/dev/xvda2', 'b', '202', '2')
 
306
#            self.run_in_target('mknod', '/dev/xvda3', 'b', '202', '3')
 
307
#            self.run_in_target('mknod', '/dev/xvc0', 'c', '204', '191')
323
308
 
324
309
    def install_from_template(self, *args, **kwargs):
325
 
        return self.vm.distro.install_from_template(*args, **kwargs)
 
310
        return self.context.install_from_template(*args, **kwargs)
326
311
 
327
312
    def run_in_target(self, *args, **kwargs):
328
 
        return self.vm.distro.run_in_target(*args, **kwargs)
 
313
        return self.context.run_in_target(*args, **kwargs)
329
314
 
330
315
    def copy_to_target(self, infile, destpath):
331
316
        logging.debug("Copying %s on host to %s in guest" % (infile, destpath))
349
334
            self.copy_to_target('/etc/default/locale', '/etc/default/locale')
350
335
        self.run_in_target('dpkg-reconfigure', '-fnoninteractive', '-pcritical', 'libc6')
351
336
        self.run_in_target('locale-gen', 'en_US')
352
 
        if self.vm.lang:
353
 
            self.run_in_target('locale-gen', self.vm.lang)
354
 
            self.install_from_template('/etc/default/locale', 'locale', { 'lang' : self.vm.lang })
 
337
        if self.context.lang:
 
338
            self.run_in_target('locale-gen', self.context.lang)
 
339
            self.install_from_template('/etc/default/locale', 'locale', { 'lang' : self.context.lang })
355
340
        self.run_in_target('dpkg-reconfigure', '-fnoninteractive', '-pcritical', 'locales')
356
341
        self.run_in_target('dpkg-reconfigure', '-pcritical', 'locales')
357
342
 
359
344
        shutil.copy(logfile, '%s/var/log/vmbuilder-install.log' % (rootdir,))
360
345
 
361
346
    def set_timezone(self):
362
 
        if self.vm.timezone:
363
 
            os.unlink('%s/etc/localtime' % self.destdir)
364
 
            shutil.copy('%s/usr/share/zoneinfo/%s' % (self.destdir, self.vm.timezone), '%s/etc/localtime' % (self.destdir,))
 
347
        timezone = self.context.get_setting('timezone')
 
348
        if timezone:
 
349
            os.unlink('%s/etc/localtime' % self.context.chroot_dir)
 
350
            shutil.copy('%s/usr/share/zoneinfo/%s' % (self.context.chroot_dir, timezone), '%s/etc/localtime' % (self.context.chroot_dir,))
365
351
 
366
352
    def install_ec2(self):
367
 
        if self.vm.ec2:
 
353
        if self.context.ec2:
368
354
            logging.debug('This suite does not support ec2')
369
355
 
370
356
    def disable_hwclock_access(self):
372
358
        fp.write('HWCLOCKACCESS=no')
373
359
        fp.close()
374
360
 
 
361
    def has_256_bit_inode_ext3_support(self):
 
362
        return False
 
363