1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 from VMBuilder import register_hypervisor, Hypervisor
21 from VMBuilder.util import run_cmd
22 import VMBuilder
23 import VMBuilder.hypervisor
24 import logging
25 import os.path
26 import stat
27
28 -class Xen(Hypervisor):
29 name = 'Xen'
30 arg = 'xen'
31 preferred_storage = VMBuilder.hypervisor.STORAGE_FS_IMAGE
32 needs_bootloader = False
33
35 destimages = []
36 for filesystem in self.vm.filesystems:
37 destfile = '%s/%s' % (self.vm.destdir, os.path.basename(filesystem.filename))
38 logging.info('Moving %s to %s' % (filesystem.filename, destfile))
39 self.vm.result_files.append(destfile)
40 run_cmd('cp', '--sparse=always', filesystem.filename, destfile)
41 os.unlink(filesystem.filename)
42 filesystem.filename = os.path.abspath(destfile)
43 destimages.append(destfile)
44
45 xenconf = '%s/xen.conf' % self.vm.destdir
46 fp = open(xenconf, 'w')
47 fp.write("""
48 # Configuration file for the Xen instance %s, created
49 # by VMBuilder
50 kernel = '%s'
51 ramdisk = '%s'
52 memory = %d
53
54 root = '/dev/xvda1 ro'
55 disk = [
56 %s
57 ]
58
59 name = '%s'
60
61 dhcp = 'dhcp'
62
63 on_poweroff = 'destroy'
64 on_reboot = 'restart'
65 on_crash = 'restart'
66
67 extra = 'xencons=tty console=tty1 console=hvc0'
68
69 """ % (self.vm.name,
70 self.vm.distro.xen_kernel_path(),
71 self.vm.distro.xen_ramdisk_path(),
72 self.vm.mem,
73 ',\n'.join(["'tap:aio:%s,xvda%d,w'" % (os.path.abspath(img), id+1) for (img, id) in zip(destimages, range(len(destimages)))]),
74 self.vm.name))
75 fp.close()
76 self.vm.result_files.append(xenconf)
77
78 register_hypervisor(Xen)
79