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 finalize(self):
34 self.imgs = [] 35 self.cmdline = ['kvm', '-m', str(self.vm.mem), '-smp', str(self.vm.cpus) ] 36 for disk in self.vm.disks: 37 img_path = disk.convert(self.vm.destdir, self.filetype) 38 self.imgs.append(img_path) 39 self.vm.result_files.append(img_path) 40 self.cmdline += ['-drive', 'file=%s' % os.path.basename(img_path)] 41 42 43 self.cmdline += ['"$@"']
44
45 - def deploy(self):
46 script = '%s/run.sh' % self.vm.destdir 47 fp = open(script, 'w') 48 fp.write("#!/bin/sh\n\nexec %s\n" % ' '.join(self.cmdline)) 49 fp.close() 50 os.chmod(script, stat.S_IRWXU | stat.S_IRWXU | stat.S_IROTH | stat.S_IXOTH) 51 self.vm.result_files.append(script)
52 53 register_hypervisor(KVM) 54