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, VMBuilderUserError 
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.vm.setting_group('VirtualBox options') 36 group.add_option('--vbox-disk-format', metavar='FORMAT', default='vdi', help='Desired disk format. Valid options are: vdi vmdk. [default: %default]') 37 self.vm.register_setting_group(group)
38
39 - def finalize(self):
40 self.imgs = [] 41 for disk in self.vm.disks: 42 img_path = disk.convert(self.vm.destdir, self.vm.vbox_disk_format) 43 self.imgs.append(img_path) 44 self.vm.result_files.append(img_path)
45
46 - def deploy(self):
47 vm_deploy_script = VMBuilder.util.render_template('virtualbox', self.vm, 'vm_deploy_script', { 'os_type' : self.vm.distro.__class__.__name__, 'vm_name' : self.vm.hostname, 'vm_disks' : self.imgs, 'memory' : self.vm.mem }) 48 49 script_file = '%s/deploy_%s.sh' % (self.vm.destdir, self.vm.hostname) 50 fp = open(script_file, 'w') 51 fp.write(vm_deploy_script) 52 fp.close() 53 os.chmod(script_file, stat.S_IRWXU | stat.S_IRGRP | stat.S_IROTH) 54 self.vm.result_files.append(script_file)
55 56 register_hypervisor(VirtualBox) 57