Discussion:
[vbox-dev] Setting linkstate using API?
Karoline Haus
2014-07-23 14:34:05 UTC
Permalink
Hi if I use VBoxManage I can disconnect a VM's virtual network cable using controlvm setlinkstate while the VM is running but I do not seem to be able to do that via the API/SDK. I don't seem to find the right commands to set. I tried to set cableConnected of INetworkAdapter but it does not allow me to change this while the VM is in running state. How can I unplug the cable via the API whilst the VM is running?

Basically I'm trying to simulate a network connection loss to the VM so that it then tries to obtain a new IP address via DHCP.

Thanks
Karoline
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.virtualbox.org/pipermail/vbox-dev/attachments/20140723/5578020a/attachment.html
Klaus Espenlaub
2014-07-23 14:50:38 UTC
Permalink
Karoline,
Post by Karoline Haus
Hi if I use VBoxManage I can disconnect a VM's virtual network cable
using controlvm setlinkstate while the VM is running but I do not seem
to be able to do that via the API/SDK. I don't seem to find the right
commands to set. I tried to set cableConnected of INetworkAdapter but it
does not allow me to change this while the VM is in running state. How
can I unplug the cable via the API whilst the VM is running?
This means you're using the wrong Machine object, or completely lack the
session handling... it works fundamentally the same way as if the VM
isn't running: create a session, get a shared lock (an exclusive one
isn't possible while the VM is running), and use the Machine reference
associated with this session.

That one is writable.
Post by Karoline Haus
Basically I'm trying to simulate a network connection loss to the VM so
that it then tries to obtain a new IP address via DHCP.
Klaus
Post by Karoline Haus
Thanks
Karoline
Karoline Haus
2014-07-24 08:29:29 UTC
Permalink
No I'm pretty sure I'm getting the right machine object and the session is valid as well. I can change other properties.

Do I have to call saveSettings() after changing cableConnected, or will it have immediate effect without calling saveSettings()?

Thanks, Karoline



Klaus Espenlaub <klaus.espenlaub at oracle.com> schrieb am 18:56 Mittwoch, 23.Juli 2014:



Karoline,
Post by Karoline Haus
Hi if I use VBoxManage I can disconnect a VM's virtual network cable
using controlvm setlinkstate while the VM is running but I do not seem
to be able to do that via the API/SDK. I don't seem to find the right
commands to set. I tried to set cableConnected of INetworkAdapter but it
does not allow me to change this while the VM is in running state. How
can I unplug the cable via the API whilst the VM is running?
This means you're using the wrong Machine object, or completely lack the
session handling... it works fundamentally the same way as if the VM
isn't running: create a session, get a shared lock (an exclusive one
isn't possible while the VM is running), and use the Machine reference
associated with this session.

That one is writable.
Post by Karoline Haus
Basically I'm trying to simulate a network connection loss to the VM so
that it then tries to obtain a new IP address via DHCP.
Klaus
Post by Karoline Haus
Thanks
Karoline
_______________________________________________
vbox-dev mailing list
vbox-dev at virtualbox.org
https://www.virtualbox.org/mailman/listinfo/vbox-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.virtualbox.org/pipermail/vbox-dev/attachments/20140724/1c75603b/attachment-0001.html
Klaus Espenlaub
2014-07-24 19:04:10 UTC
Permalink
Karoline,
Post by Karoline Haus
No I'm pretty sure I'm getting the right machine object and the
session is valid as well. I can change other properties.
Mysterious... VBoxManage doesn't do anything special in this area.

https://www.virtualbox.org/browser/vbox/trunk/src/VBox/Frontends/VBoxManage/VBoxManageControlVM.cpp#L344
Post by Karoline Haus
Do I have to call saveSettings() after changing cableConnected, or
will it have immediate effect without calling saveSettings()?
The usual rules for runtime settings changes apply: they take immediate
effect, but it's good practice to save such settings. Many do that
automatically (which is kind of inconsistent), but if you can't change
the setting you want it's irrelevant to talk about saving.

Klaus
Post by Karoline Haus
Thanks, Karoline
Karoline,
Post by Karoline Haus
Hi if I use VBoxManage I can disconnect a VM's virtual network cable
using controlvm setlinkstate while the VM is running but I do not seem
to be able to do that via the API/SDK. I don't seem to find the right
commands to set. I tried to set cableConnected of INetworkAdapter but it
does not allow me to change this while the VM is in running state. How
can I unplug the cable via the API whilst the VM is running?
This means you're using the wrong Machine object, or completely lack the
session handling... it works fundamentally the same way as if the VM
isn't running: create a session, get a shared lock (an exclusive one
isn't possible while the VM is running), and use the Machine reference
associated with this session.
That one is writable.
Post by Karoline Haus
Basically I'm trying to simulate a network connection loss to the VM so
that it then tries to obtain a new IP address via DHCP.
Klaus
Post by Karoline Haus
Thanks
Karoline
<mailto:vbox-dev at virtualbox.org><https://www.virtualbox.org/mailman/listinfo/vbox-dev>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.virtualbox.org/pipermail/vbox-dev/attachments/20140724/1290e997/attachment.html
Loading...