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

Source Code for Module VMBuilder.plugins.kvm.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  import VMBuilder 
21  import os 
22  import stat 
23   
24 -class KVM(Hypervisor):
25 name = 'KVM' 26 arg = 'kvm' 27 filetype = 'qcow2' 28 preferred_storage = VMBuilder.hypervisor.STORAGE_DISK_IMAGE 29 needs_bootloader = True 30
31 - def register_options(self):
32 group = self.setting_group('VM settings') 33 group.add_setting('mem', extra_args=['-m'], type='int', default=128, help='Assign MEM megabytes of memory to the guest vm. [default: %default]') 34 group.add_setting('cpus', type='int', default=1, help='Assign NUM cpus to the guest vm. [default: %default]')
35
36 - def convert(self, disks, destdir):
37 self.imgs = [] 38 self.cmdline = ['kvm', '-m', str(self.context.get_setting('mem'))] 39 self.cmdline += ['-smp', str(self.context.get_setting('cpus'))] 40 for disk in disks: 41 img_path = disk.convert(destdir, self.filetype) 42 self.imgs.append(img_path) 43 self.call_hooks('fix_ownership', img_path) 44 self.cmdline += ['-drive', 'file=%s' % os.path.basename(img_path)] 45 46 self.cmdline += ['"$@"']
47
48 - def deploy(self, destdir):
49 # No need create run script if vm is registered with libvirt 50 if self.context.get_setting('libvirt'): 51 return 52 53 script = '%s/run.sh' % destdir 54 fp = open(script, 'w') 55 fp.write("#!/bin/sh\n\nexec %s\n" % ' '.join(self.cmdline)) 56 fp.close() 57 os.chmod(script, stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH | stat.S_IXOTH) 58 self.call_hooks('fix_ownership', script)
59
61 return 'kvm'
62
63 -class QEMu(KVM):
64 name = 'QEMu' 65 arg = 'qemu' 66
68 return 'qemu'
69 70 register_hypervisor(KVM) 71 register_hypervisor(QEMu) 72