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