1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
29 preferred_storage = VMBuilder.hypervisor.STORAGE_DISK_IMAGE
30 needs_bootloader = True
31 name = 'VirtualBox'
32 arg = 'vbox'
33
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
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
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