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('VirtualBox options') 36 group.add_setting('mem', extra_args=['-m'], type='int', default=128, help='Assign MEM megabytes of memory to the guest vm. [default: %default]') 37 group.add_setting('cpus', type='int', default=1, help='Assign NUM cpus to the guest vm. [default: %default]') 38 group.add_setting('vbox-disk-format', metavar='FORMAT', default='vdi', help='Desired disk format. Valid options are: vdi vmdk. [default: %default]')
39
40 - def convert(self, disks, destdir):
41 self.imgs = [] 42 for disk in disks: 43 img_path = disk.convert(destdir, self.context.get_setting('vbox-disk-format')) 44 self.imgs.append(img_path)
45
46 - def deploy(self,destdir):
47 hostname = self.context.distro.get_setting('hostname') 48 mac = self.context.get_setting('mac') 49 ip = self.context.get_setting('ip') 50 vm_deploy_script = VMBuilder.util.render_template('virtualbox', self.context, 'vm_deploy_script', { 'os_type' : self.context.distro.__class__.__name__, 'vm_name' : hostname, 'vm_disks' : self.imgs, 'memory' : self.context.get_setting('mem'), 'cpus' : self.context.get_setting('cpus') }) 51 52 script_file = '%s/deploy_%s.sh' % (destdir, hostname) 53 fp = open(script_file, 'w') 54 fp.write(vm_deploy_script) 55 fp.close() 56 os.chmod(script_file, stat.S_IRWXU | stat.S_IRGRP | stat.S_IROTH) 57 self.context.result_files.append(script_file)
58 59 register_hypervisor(VirtualBox) 60