def install_iso(self): """Boot VM on ISO image.""" # Insert DVD drive into VM. execute_command('VBoxManage storageattach %(vm_id)s --storagectl IDE ' \ '--type dvddrive --medium %(installer_iso)s --port 0 ' \ '--device 0' % self.options) # Start VM. execute_command('VBoxManage startvm %(vm_id)s --type gui' \ % self.options)
def package_box(self): """Package Vagrant box.""" # Create output directory if necessary. dirname = os.path.dirname(self.options['vagrant_box']) if not os.path.exists(dirname): os.makedirs(dirname) with use_temp_dir() as temp_output_dir: temp_output_file = os.path.join(temp_output_dir, 'package.box') arguments = [] arguments.append('--base %(vm_id)s' % self.options) arguments.append('--output %s' % temp_output_file) if self.options['vagrant_file']: arguments.append('--vagrantfile %(vagrant_file)s' \ % self.options) command = 'vagrant package %s' % ' '.join(arguments) execute_command(command) shutil.copy2(temp_output_file, self.options['vagrant_box'])
def delete_vm(self): execute_command('VBoxManage unregistervm %(vm_id)s --delete' \ % self.options)
def create_vm(self): """Create a new VirtualBox VM.""" # Create and register box. execute_command('VBoxManage createvm --name %(vm_id)s ' \ '--ostype %(vm_os_type)s --register ' \ '--basefolder "%(vm_folder)s"' % self.options) # Set box's ram and cpu. execute_command('VBoxManage modifyvm %(vm_id)s --vrde off ' \ '--vram %(vm_vram)d --memory %(vm_ram)d ' \ '--cpus %(vm_cpus)d' % self.options) # Configure hard disk. execute_command('VBoxManage storagectl %(vm_id)s --name SATA --add ' \ 'sata --bootable on' % self.options) execute_command('VBoxManage createhd --filename %(vm_disk_file)s ' \ '--size %(vm_disk_size)d --format VDI ' \ '--variant Standard' % self.options) execute_command('VBoxManage storageattach %(vm_id)s ' \ '--storagectl SATA --port 0 --device 0 --type hdd ' \ '--medium "%(vm_disk_file)s"' % self.options) # Add IDE controller execute_command('VBoxManage storagectl %(vm_id)s --name IDE --add ' \ 'ide --controller PIIX4 --hostiocache on ' \ '--bootable on' % self.options)