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-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  import VMBuilder 
22  import VMBuilder.hypervisor 
23  import os 
24  import os.path 
25  import stat 
26   
27 -class KVM(Hypervisor):
28 name = 'KVM' 29 arg = 'kvm' 30 filetype = 'qcow2' 31 preferred_storage = VMBuilder.hypervisor.STORAGE_DISK_IMAGE 32 needs_bootloader = True 33
34 - def finalize(self):
35 self.imgs = [] 36 self.cmdline = ['kvm', '-m', str(self.vm.mem), '-smp', str(self.vm.cpus) ] 37 for disk in self.vm.disks: 38 img_path = disk.convert(self.vm.destdir, self.filetype) 39 self.imgs.append(img_path) 40 self.vm.result_files.append(img_path) 41 self.cmdline += ['-drive', 'file=%s' % os.path.basename(img_path)] 42 43 44 self.cmdline += ['"$@"']
45
46 - def deploy(self):
47 script = '%s/run.sh' % self.vm.destdir 48 fp = open(script, 'w') 49 fp.write("#!/bin/sh\n\nexec %s\n" % ' '.join(self.cmdline)) 50 fp.close() 51 os.chmod(script, stat.S_IRWXU | stat.S_IRWXU | stat.S_IROTH | stat.S_IXOTH) 52 self.vm.result_files.append(script)
53 54 register_hypervisor(KVM) 55