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-2008 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 as published by 
 9  #    the Free Software Foundation, either version 3 of the License, or 
10  #    (at your option) any later version. 
11  # 
12  #    This program is distributed in the hope that it will be useful, 
13  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
14  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
15  #    GNU General Public License for more details. 
16  # 
17  #    You should have received a copy of the GNU General Public License 
18  #    along with this program.  If not, see <http://www.gnu.org/licenses/>. 
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
34 - def finalize(self):
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