Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mjdorma/6988895 to your computer and use it in GitHub Desktop.
Save mjdorma/6988895 to your computer and use it in GitHub Desktop.
pyvbox: set attachment type of network adapter for VirtualBox machine to "host_only"
"""pyvbox:How to set the attachment_type of a network adapter.
"""
import virtualbox
from virtualbox.library import NetworkAttachmentType
# Option 1
vbox = virtualbox.VirtualBox()
machine = vbox.find_machine('test_vm')
session = machine.create_session()
adapter = session.machine.get_network_adapter(0)
adapter.attachment_type = NetworkAttachmentType.host_only
session.machine.save_settings()
session.unlock_machine()
# Option 2
vbox = virtualbox.VirtualBox()
machine = vbox.find_machine('test_vm')
with machine.create_session() as session:
adapter = session.machine.get_network_adapter(0)
adapter.attachment_type = NetworkAttachmentType.host_only
session.machine.save_settings()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment