mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 07:26:29 +00:00
vbox instance creation working
This commit is contained in:
parent
a8e5c2d6e4
commit
ea3eeae064
3 changed files with 39 additions and 34 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import virtualbox
|
||||||
|
|
||||||
|
|
||||||
class Image(object):
|
class Image(object):
|
||||||
|
@ -14,12 +15,11 @@ class VirtualBoxImage(Image):
|
||||||
def __init__(self, manifest, image_path):
|
def __init__(self, manifest, image_path):
|
||||||
super(VirtualBoxImage, self).__init__(manifest)
|
super(VirtualBoxImage, self).__init__(manifest)
|
||||||
self.image_path = image_path
|
self.image_path = image_path
|
||||||
self.medium = self.vbox.open_medium(location=self.image.image_path,
|
self.vbox = virtualbox.VirtualBox()
|
||||||
decive_type=self.vbox.library.DeviceType.HardDisk,
|
self.medium = self.vbox.open_medium(self.image_path, # location
|
||||||
access_mode=self.vbox.library.AccessMode.read_only,
|
virtualbox.library.DeviceType.hard_disk, # decive_type
|
||||||
force_new_uuid=False)
|
virtualbox.library.AccessMode.read_only, # access_mode
|
||||||
|
False) # force_new_uuid
|
||||||
|
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
self.medium.delete_storage()
|
self.medium.close()
|
||||||
import os
|
|
||||||
os.remove(self.image_path)
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from bootstrapvz.common.tools import log_check_call
|
from bootstrapvz.common.tools import log_check_call
|
||||||
|
import virtualbox
|
||||||
|
|
||||||
|
|
||||||
class Instance(object):
|
class Instance(object):
|
||||||
|
@ -24,11 +25,12 @@ class VirtualBoxInstance(Instance):
|
||||||
|
|
||||||
def __init__(self, name, image):
|
def __init__(self, name, image):
|
||||||
super(VirtualBoxInstance, self).__init__(name, image)
|
super(VirtualBoxInstance, self).__init__(name, image)
|
||||||
import virtualbox
|
|
||||||
self.vbox = virtualbox.VirtualBox()
|
self.vbox = virtualbox.VirtualBox()
|
||||||
|
manager = virtualbox.Manager()
|
||||||
|
self.session = manager.get_session()
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
if self.image.manifest['system']['architecture'] == 'x86':
|
if self.image.manifest.system['architecture'] == 'x86':
|
||||||
os_type = 'Debian'
|
os_type = 'Debian'
|
||||||
else:
|
else:
|
||||||
os_type = 'Debian_64'
|
os_type = 'Debian_64'
|
||||||
|
@ -37,27 +39,19 @@ class VirtualBoxInstance(Instance):
|
||||||
self.machine.save_settings()
|
self.machine.save_settings()
|
||||||
self.machine.cpu_count = self.cpus
|
self.machine.cpu_count = self.cpus
|
||||||
self.machine.memory_size = self.memory
|
self.machine.memory_size = self.memory
|
||||||
self.machine.attach_device(name='root', controller_port=0, device=0,
|
|
||||||
type_p=self.vbox.library.DeviceType.HardDisk,
|
|
||||||
medium=self.image.medium)
|
|
||||||
self.vbox.register_machine(self.machine)
|
self.vbox.register_machine(self.machine)
|
||||||
# [self.uuid] = log_check_call(['VBoxManage', 'createvm'
|
self.machine.lock_machine(self.session, virtualbox.library.LockType.write)
|
||||||
# '--name', self.name])
|
strg_ctrl = self.session.machine.add_storage_controller('SATA Controller',
|
||||||
# log_check_call(['VBoxManage', 'modifyvm', self.uuid,
|
virtualbox.library.StorageBus.sata)
|
||||||
# '--cpus', self.cpus,
|
strg_ctrl.port_count = 1
|
||||||
# '--memory', self.memory])
|
self.session.machine.attach_device(name='SATA Controller', controller_port=0, device=0,
|
||||||
# log_check_call(['VBoxManage', 'storageattach', self.uuid,
|
type_p=virtualbox.library.DeviceType.hard_disk,
|
||||||
# '--storagectl', '"SATA Controller"',
|
medium=self.image.medium)
|
||||||
# '--device', '0',
|
self.session.machine.save_settings()
|
||||||
# '--port', '0',
|
self.session.unlock_machine()
|
||||||
# '--type', 'hdd',
|
|
||||||
# '--medium', self.image.image_path])
|
|
||||||
|
|
||||||
def boot(self):
|
def boot(self):
|
||||||
self.session = self.vbox.Session()
|
|
||||||
self.machine.launch_vm_process(self.session, 'headless')
|
self.machine.launch_vm_process(self.session, 'headless')
|
||||||
# log_check_call(['VBoxManage', 'startvm', self.uuid,
|
|
||||||
# '--type', 'headless'])
|
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
self.session.console.power_down()
|
self.session.console.power_down()
|
||||||
|
@ -65,5 +59,10 @@ class VirtualBoxInstance(Instance):
|
||||||
'--type', 'headless'])
|
'--type', 'headless'])
|
||||||
|
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
self.machine.unregister(self.vbox.CleanupMode.full)
|
if hasattr(self, 'machine'):
|
||||||
self.machine.remove(delete=True)
|
self.machine.lock_machine(self.session, virtualbox.library.LockType.write)
|
||||||
|
self.session.machine.detach_device(name='SATA Controller', controller_port=0, device=0)
|
||||||
|
self.session.machine.save_settings()
|
||||||
|
self.session.unlock_machine()
|
||||||
|
self.machine.unregister(virtualbox.library.CleanupMode.unregister_only)
|
||||||
|
self.machine.remove(delete=True)
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import tools
|
import tools
|
||||||
|
import tools.images
|
||||||
|
import tools.instances
|
||||||
from manifests import partials
|
from manifests import partials
|
||||||
from bootstrapvz.base.manifest import Manifest
|
from bootstrapvz.base.manifest import Manifest
|
||||||
from bootstrapvz.remote.build_servers import pick_build_server
|
from bootstrapvz.remote.build_servers import pick_build_server
|
||||||
|
@ -39,14 +41,18 @@ volume:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
image = tools.images.VirtualBoxImage(manifest, image_path)
|
image = tools.images.VirtualBoxImage(manifest, image_path)
|
||||||
|
try:
|
||||||
|
instance = tools.instances.VirtualBoxInstance('unpartitioned_extlinux', image)
|
||||||
|
instance.create()
|
||||||
|
# instance.boot()
|
||||||
|
|
||||||
instance = tools.instances.VirtualBoxInstance(image)
|
# tools.test(instance)
|
||||||
instance.create()
|
|
||||||
instance.boot()
|
|
||||||
|
|
||||||
tools.test(instance)
|
finally:
|
||||||
|
if 'instance' in locals():
|
||||||
|
instance.destroy()
|
||||||
finally:
|
finally:
|
||||||
if 'instance' in locals():
|
|
||||||
instance.destroy()
|
|
||||||
if 'image' in locals():
|
if 'image' in locals():
|
||||||
image.destroy()
|
image.destroy()
|
||||||
|
import os
|
||||||
|
os.remove(image_path)
|
||||||
|
|
Loading…
Add table
Reference in a new issue