Reputation: 161
How can I start a virtual machine from virtualbox as headless using pyvb
modules?
Upvotes: 3
Views: 12843
Reputation: 627
If you use the library pyvbox the task you want to achieve is very simple:
import virtualbox
vbox = virtualbox.VirtualBox()
machine = vbox.find_machine("you_virtual_machine_name") ## for example: "ubuntu"
# If you want to run it normally:
proc = machine.launch_vm_process(session, "gui")
# If you want to run it in background:
# proc = machine.launch_vm_process(session, "headless")
proc.wait_for_completion(timeout=-1)
Upvotes: 0
Reputation: 5350
YOu can use the pyvbox
python module to startup and stop virtualboxes using the Vbox interaface:
https://pypi.python.org/pypi/pyvbox
Upvotes: 0
Reputation: 12590
You can use the real python bindings instead (and not a wrapper that call the VBoxManager command line in a subprocess, say pyvb) relatively easily by using the vboxshell.py script from virtual box.
Or you can use it for reference documentation of the python bindings. There's no documentation for the python bindings and honestly they are not implemented in a good pythonic way. Attributes and methods are not present in the __dict__
, so it's not possible to find them by introspection (or autocompletion in ipython) and there's no docstring either. Another reference for the python bindings are the source code of the vboxweb project here: VBoxWebSrv.py
For the headless startup, you need to pass 'headless' to the third argument (type) of the vbox.openRemoteSession(session, uuid, type, "") method call. Look at startVm() function in vboxshell.py and VBoxWebSrv.py for reference.
Upvotes: 11