Launch a machine remotely with Python

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
milan
Posts: 4
Joined: 1. Mar 2016, 23:59

Launch a machine remotely with Python

Post by milan »

Hi everyone,
I'm new to VirtualBox API and I'm trying to launch a virtual machine remotely via VBoxWebSrv.exe, which is running locally (for testing).
I've done this so far:

Code: Select all

from vboxapi import *
params = {'ur*' : 'ht*p://localhost/', # I'm not allowed to post links in this thread (it is my first)
          'user' : 'user',
          'password' : 'password'
          }
webmgr = VirtualBoxManager('WEBSERVICE', params)
vbox = webmgr.getVirtualBox()
machines = vbox.getMachines()

for mach in machines:
    session = webmgr.getSessionObject(vbox)
    # What method to call now?
I have found out that there is no method LaunchVMProcess as there is for COM. I also tried to

Code: Select all

progress = vbox.openRemoteSession(session, mach.id, 'WRITE', {})
but I'm getting the following error from ZSI:

Code: Select all

ZSI\client.py", line 503, in Receive
File "build\bdist.win32\egg\ZSI\client.py", line 431, in Receive
ZSI.FaultException: Method 'ns1:IVirtualBox_openRemoteSession' not implemented: method name or namespace not recognized
None
Is there any way to solve this?

Thanks
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: Launch a machine remotely with Python

Post by noteirak »

Looking at the python samples provided in the SDK, the machine object does have a launchVMProcess method.

The sample I'm looking at is in the 5.0.14 SDK ZIP with internal location /sdk/bindings/glue/python/sample/vboxshell.py
The specific code example is the method startVm() located around line 262

From what I see, nothing different from the other binding languages...
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
milan
Posts: 4
Joined: 1. Mar 2016, 23:59

Re: Launch a machine remotely with Python

Post by milan »

Yes, I know that there is launchVMProcess in vboxapi/__init__.py and it works fine, when I try to launch VM via COM, but the problem occurs when I want to run things with webservice since it uses VirtuaBox_wrappers.py. When I put the line

Code: Select all

progress = mach.launchVMProcess(session, "", "")
right after the "# What method to call now?" line from the code above, I get the following error:

Code: Select all

Traceback (most recent call last):
  File "C:\Users\Milan\git\VirtualBox-Manager\VirtualBox_Manager\src\test.py", line 45, in <module>
    progress = mach.launchVMProcess(session, "", "")
  File "C:\Program Files\Oracle\VirtualBox\sdk\bindings\webservice\python\lib\VirtualBox_wrappers.py", line 1801, in __getattr__
    return IUnknown.__getattr__(self, name)
  File "C:\Program Files\Oracle\VirtualBox\sdk\bindings\webservice\python\lib\VirtualBox_wrappers.py", line 388, in __getattr__
    raise AttributeError
AttributeError
and I have no idea why.
I have looked onto the example you reffered me to and that one does not work for me as well :/
It does the following thing.

Code: Select all

C:\Program Files\Oracle\VirtualBox\sdk\bindings\glue\python\sample>python vboxshell.py 
Running VirtualBox version 5.0.14
vbox> start "Mint 17"
'<win32com.gen_py.VirtualBox Type Library.IVirtualBox instance at 0x38071712>' object has
no attribute 'openRemoteSession'
vbox>
Mint 17 is the only registered VM on my machine.
milan
Posts: 4
Joined: 1. Mar 2016, 23:59

Re: Launch a machine remotely with Python

Post by milan »

The issue seems to be solved with a new release of SDK 5.0.16. I can now launch a virtual machine via webservice.
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: Launch a machine remotely with Python

Post by noteirak »

Great! Thanks for reporting back
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Post Reply