launchVMProcess environment variables

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
JJon
Posts: 18
Joined: 3. Nov 2016, 11:54

launchVMProcess environment variables

Post by JJon »

Hi,

The documentation specifies that IMachine::launchVMProcess method can have an environment argument which "will be appended to the
environment of the VirtualBox server process".

I'm using the Java web serice and I tried passing some variables like: "RETURN_IP=\"1.2.3.4\"", but couldn't find those variables in the guest VM that was started.
I tried finding where those variables were appended but couldn't use them even in the VBox main machine.

How can I use this?
Is there any possibility to pass some variables to the guest machine that is started with "launchVMProcess"? Any other way to do it?

Thanks,
Jonathan
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: launchVMProcess environment variables

Post by noteirak »

Are you trying to see the environment variables in the guest OS? If that's the case, it wouldn't work.
Those environment variables are only visible to the process running the VM itself.

What are you trying to achieve exactly?
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
JJon
Posts: 18
Joined: 3. Nov 2016, 11:54

Re: launchVMProcess environment variables

Post by JJon »

Yes, I thought it would be visible to the guest.
Those environment variables are only visible to the process running the VM itself.
What process is this? The one that runs the web service?


My goal is to somehow pass information from the calling process to the guest OS so it can know its name or the IP of the calling machine so it can notify it when it's ready for calls (the OS startup can take time).
Is there anyway to do it?

Thanks,
jonathan
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: launchVMProcess environment variables

Post by noteirak »

That wouldn't be the process running the webservices.
Depending on your front-end, it would typically be VirtualBox or VBoxHeadless.

To pass data from the host to the guest, you can use Guest Properties.

In the API, this is doable via IMachine::setGuestProperrty and other related methods https://www.virtualbox.org/sdkref/inter ... 417a7bb888
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
JJon
Posts: 18
Joined: 3. Nov 2016, 11:54

Re: launchVMProcess environment variables

Post by JJon »

The problem is that in order for the guest to read a guestproperty from the API it needs at least to know the name of the VM it resides in. This is not static in my case. There can be numerous VMs with different names which are dynamically allocated.
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: launchVMProcess environment variables

Post by noteirak »

given the fact you need to have the name or the UUID of the VM to be able to use launchVMProcess, I'm not sure how you wouldn't be able to also set a guest property before/after starting the said VM?
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
JJon
Posts: 18
Joined: 3. Nov 2016, 11:54

Re: launchVMProcess environment variables

Post by JJon »

Setting the property will be easy.
Getting it from the guest VM is more tricky if I don't know the name inside the guest.
Am I missing something?
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: launchVMProcess environment variables

Post by noteirak »

I think you are. I'm guessing you want to use some auto-provisioning mechanism of your guests and communicate the IP that should be set on one of the NICs.
In that case, you would set always the same guest property on each VM with the approprivate value. e.g. "/MyNamespace/Provisioning/IP" and value "1.2.3.4".
The guest property name is totally arbitrary and up to you. You will see that VirtualBox already sets some using the /VirtualBox namespace.

From inside the guest, you just need to read the same guest property, which value is unique to that VM (this is NOT shared across the VirtualBox installation!)
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
JJon
Posts: 18
Joined: 3. Nov 2016, 11:54

Re: launchVMProcess environment variables

Post by JJon »

From inside the guest, you just need to read the same guest property
Here is where I fail to understand. In order to read the guest property I need to know the VM name in order to request it from the web service API.
However, this name is not known to the guest since the guest is inside a VM that was dynamically allocated.
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: launchVMProcess environment variables

Post by noteirak »

You don't connect to the web services from the guest! you use the guest additions' binary VBoxControl which directly talks to VirtualBox and provide the matching guest properties!
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
JJon
Posts: 18
Joined: 3. Nov 2016, 11:54

Re: launchVMProcess environment variables

Post by JJon »

Ahh.. That's what I was missing...

Can VBoxControl commands be called using Java API?
Any documentation on that?

Thanks,
Jonathan
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: launchVMProcess environment variables

Post by noteirak »

There is no direct interfacing with VBoxControl (which is only available in the guest) but you can always simply run the process in Java directly and read its STDOUT/STDERR
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
JJon
Posts: 18
Joined: 3. Nov 2016, 11:54

Re: launchVMProcess environment variables

Post by JJon »

Thanks!
Post Reply