开发者

Starting VirtualBox VM using Python

How can I start a virtual machine from virtualbox as headless using pyvb 开发者_开发知识库modules?


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.


YOu can use the pyvbox python module to startup and stop virtualboxes using the Vbox interaface:

https://pypi.python.org/pypi/pyvbox


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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜