Package VMBuilder :: Package plugins :: Package xen :: Module vm
[frames] | no frames]

Source Code for Module VMBuilder.plugins.xen.vm

 1  # 
 2  #    Uncomplicated VM Builder 
 3  #    Copyright (C) 2007-2009 Canonical Ltd. 
 4  # 
 5  #    See AUTHORS for list of contributors 
 6  # 
 7  #    This program is free software: you can redistribute it and/or modify 
 8  #    it under the terms of the GNU General Public License version 3, as 
 9  #    published by the Free Software Foundation. 
10  # 
11  #    This program is distributed in the hope that it will be useful, 
12  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
13  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
14  #    GNU General Public License for more details. 
15  # 
16  #    You should have received a copy of the GNU General Public License 
17  #    along with this program.  If not, see <http://www.gnu.org/licenses/>. 
18  # 
19  from   VMBuilder      import register_hypervisor, Hypervisor 
20  from   VMBuilder.util import run_cmd 
21  import VMBuilder 
22  import VMBuilder.hypervisor 
23  import logging 
24  import os.path 
25   
26 -class Xen(Hypervisor):
27 name = 'Xen' 28 arg = 'xen' 29 preferred_storage = VMBuilder.hypervisor.STORAGE_FS_IMAGE 30 needs_bootloader = False 31
32 - def register_options(self):
33 group = self.setting_group('Xen options') 34 group.add_setting('xen-kernel', metavar='PATH', help='Path to the kernel to use (e.g.: /boot/vmlinux-2.6.27-7-server). Default depends on distribution and suite') 35 group.add_setting('xen-ramdisk', metavar='PATH', help='Path to the ramdisk to use (e.g.: /boot/initrd.img-2.6.27-7-server). Default depends on distribution and suite.') 36 group.add_setting('mem', extra_args=['-m'], type='int', default=128, help='Assign MEM megabytes of memory to the guest vm. [default: %default]')
37
38 - def convert(self, filesystems, destdir):
39 destimages = [] 40 for filesystem in filesystems: 41 if not filesystem.preallocated: 42 destfile = '%s/%s' % (destdir, os.path.basename(filesystem.filename)) 43 logging.info('Moving %s to %s' % (filesystem.filename, destfile)) 44 run_cmd('cp', '--sparse=always', filesystem.filename, destfile) 45 self.call_hooks('fix_ownership', destfile) 46 os.unlink(filesystem.filename) 47 filesystem.filename = os.path.abspath(destfile) 48 destimages.append(destfile) 49 50 if not self.context.get_setting('xen-kernel'): 51 self.context.xen_kernel = self.context.distro.xen_kernel_path() 52 if not self.context.get_setting('xen-ramdisk'): 53 self.context.xen_ramdisk = self.context.distro.xen_ramdisk_path() 54 55 xenconf = '%s/xen.conf' % destdir 56 fp = open(xenconf, 'w') 57 fp.write(""" 58 # Configuration file for the Xen instance %s, created 59 # by VMBuilder 60 kernel = '%s' 61 ramdisk = '%s' 62 memory = %d 63 64 root = '/dev/xvda1 ro' 65 disk = [ 66 %s 67 ] 68 69 name = '%s' 70 71 dhcp = 'dhcp' 72 vif = [''] 73 74 on_poweroff = 'destroy' 75 on_reboot = 'restart' 76 on_crash = 'restart' 77 78 extra = 'xencons=tty console=tty1 console=hvc0' 79 80 """ % (self.context.distro.get_setting('hostname'), 81 self.context.get_setting('xen-kernel'), 82 self.context.get_setting('xen-ramdisk'), 83 self.context.get_setting('mem'), 84 ',\n'.join(["'tap:aio:%s,xvda%d,w'" % (os.path.abspath(img), id+1) for (img, id) in zip(destimages, range(len(destimages)))]), 85 self.context.distro.get_setting('hostname'))) 86 fp.close() 87 self.call_hooks('fix_ownership', xenconf)
88 89 register_hypervisor(Xen) 90