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

Source Code for Module VMBuilder.plugins.virtualbox.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   
20  import os 
21  import os.path 
22  import stat 
23  import VMBuilder 
24  from   VMBuilder      import register_hypervisor, Hypervisor 
25  from   VMBuilder.disk import vbox_manager_path 
26  import VMBuilder.hypervisor 
27   
28 -class VirtualBox(Hypervisor):
29 preferred_storage = VMBuilder.hypervisor.STORAGE_DISK_IMAGE 30 needs_bootloader = True 31 name = 'VirtualBox' 32 arg = 'vbox' 33
34 - def register_options(self):
35 group = self.setting_group('VM settings') 36 group.add_setting('vbox-disk-format', metavar='FORMAT', default='vdi', help='Desired disk format. Valid options are: vdi vmdk. [default: %default]')
37
38 - def finalize(self):
39 self.imgs = [] 40 for disk in self.context.disks: 41 img_path = disk.convert(self.context.destdir, self.context.vbox_disk_format) 42 self.imgs.append(img_path) 43 self.context.result_files.append(img_path)
44
45 - def deploy(self):
46 vm_deploy_script = VMBuilder.util.render_template('virtualbox', self.context, 'vm_deploy_script', { 'os_type' : self.context.distro.__class__.__name__, 'vm_name' : self.context.hostname, 'vm_disks' : self.imgs, 'memory' : self.context.mem, 'cpus' : self.context.cpus }) 47 48 script_file = '%s/deploy_%s.sh' % (self.context.destdir, self.context.hostname) 49 fp = open(script_file, 'w') 50 fp.write(vm_deploy_script) 51 fp.close() 52 os.chmod(script_file, stat.S_IRWXU | stat.S_IRGRP | stat.S_IROTH) 53 self.context.result_files.append(script_file)
54 55 register_hypervisor(VirtualBox) 56