PYVBOX Can't Launch Machine

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
AlanR917
Posts: 3
Joined: 25. Jun 2016, 21:46

PYVBOX Can't Launch Machine

Post by AlanR917 »

Hello everyone, sorry if this is the wrong place to ask, I wasn't sure exactly where to put this. I am having troubles launching a VM. When I try to start the VM like this:

Code: Select all

import virtualbox 
vm = virtualbox.VirtualBox().find_machine('test') 
session = vm.create_session() 
s = virtualbox.Session() 
vm.launch_vm_process()
I get an error saying

Code: Select all

(The machine 'test' is already locked by a session (or being locked or unlocked))
When I try to unlock the machine, it says that it's not locked.

But then when I try to lock it, using this command:

Code: Select all

vm.create_session(lock_type=virtualbox.library.LockType.write)
I get the following error:

Code: Select all

Failed to create clone - 0x80bb0007 (The machine 'test' is already locked for a session (or being unlocked))
I am using Virtualbox Version 5.0.18_Debian r106667.

Can anyone help me with 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: PYVBOX Can't Launch Machine

Post by noteirak »

I'm not a Python expert but it looks to me like you lock the VM before doing the power on call, which you shouldn't do.
You should pass the session object you get from your VirtualBoxobjet to the powerOn method of the VM.

See the code samples page for Java code example. The SDK archive has Python example as far as I know.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
AlanR917
Posts: 3
Joined: 25. Jun 2016, 21:46

Re: PYVBOX Can't Launch Machine

Post by AlanR917 »

Thanks for the response!

Even when I don't specifically lock it, it still has issues launching. I'm still new to how vbox programming works. Does it automatically lock the VM before it launches? I'm assuming it would, otherwise other programs could potentially use it, which we don't want. Also, I looked at all the documentation, and I literally copied and pasted those few lines and it still doesn't work. I had it working before, but then something happened and now it won't launch. My guess is that it may be something with virtualbox itself, as I did have it working with the same code, but then it somehow just stopped working.
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: PYVBOX Can't Launch Machine

Post by noteirak »

The way it normally works is:
- Get regular VM object
- Get session object from IVirtualBox, but don't lock the VM.
- call launchVMProcess on the regular VM object and give it 3 arguments: the session object, the front-end type and finally env related parameters. Usually the 3rd is null, so that leave the session object and then "headless" or "gui" for the 2nd.
- You get back a IProgress object on which you check until VM is started
- At this point, the session object you created has a shared lock on the VM and the process running the VM has a Write lock (to be precise, a VM type of lock, but from your point of view, it's like a Write one).
- You need to release that lock if you're not going to use it directly

While I don't have a python sample, have a look at the Samples topic in 4.3 section for an example of starting a headless VM. This code works as is for 5.0 and 5.1, putting aside any imports.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
AlanR917
Posts: 3
Joined: 25. Jun 2016, 21:46

Re: PYVBOX Can't Launch Machine

Post by AlanR917 »

Thank you! I'll give it a go.
Post Reply