sethmlarson / virtualbox-python

Complete implementation of VirtualBox's COM API with a Pythonic interface.
https://pypi.org/project/virtualbox
Apache License 2.0
354 stars 75 forks source link

toggle setlinkstate with python #160

Closed Transmitt0r closed 2 years ago

Transmitt0r commented 2 years ago

Hello,

I'm trying to disconnect and reconnect the network adapter to my VM. (Sadly this is necessary to get the network stack running). I found this solution for the CLI and the command VBoxManage controlvm "MyVM" setlinkstate1 off works fine for me, but now I want to do the same with python and got stuck.

I tried to toggle the adapter like this:

network_adapter = session.machine.get_network_adapter(0)
network_adapter.enabled = False
network_adapter.enabled = True

but get an error message that the machine is running and immutable. Any advice?

Thanks in advance!

EDIT: If anyone else is stumbling over this, it should be network_adapter.cable_connected instead!