how to activate network card on vbox machines

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
Dmouha
Posts: 11
Joined: 12. Aug 2015, 11:04

how to activate network card on vbox machines

Post by Dmouha »

Hello,
I'm having a hard time to activate a network card using virtualbox python API. My virtual machine template has only 1 nic (that is nat).
I would like to activate the nic 2 and put a hostonly network vboxnet0

My configuration is below:
OS: Ubntu14
Virtualbox: version 5.0.2r102096
API used : python pyvbox API


Thanks for the help
:D
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: how to activate network card on vbox machines

Post by noteirak »

Here how you would do it in Java :

Code: Select all

// We assume VM is locked with LockType.Write
IMachine vm = session.getMachine();
INetworkAdapter nic = vm.getNetworkAdapter(1L); // index starts at 0
nic.setEnabled(true);
nic.setHostOnlyInterface("vboxnet0");
vm.saveSettings();
// Don't forget to unlock the machine
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Dmouha
Posts: 11
Joined: 12. Aug 2015, 11:04

Re: how to activate network card on vbox machines

Post by Dmouha »

Do I have first to create and attach a virtual network ?
If so how can I do that ? I tried by instanciating an network adapter but did not suceeded.
I tried this below (activating it directly without attachinf a virtual network)

Code: Select all

import time
import virtualbox
from virtualbox.library import StorageBus, IMachine
from virtualbox.library import IStorageController, LockType
from virtualbox.library import IVirtualBox, AccessMode

session = virtualbox.Session()
vbox = virtualbox.VirtualBox()
vm = vbox.find_machine("test")
vm.lock_machine(session, LockType.write)
help(session.machine)

session.machine.get_network_adapter(0)
<virtualbox.library.INetworkAdapter object at 0x7ff20d513f50>
session.machine.get_network_adapter(0).enabled
True
session.machine.get_network_adapter(1).enabled = True
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/virtualbox/library.py", line 21240, in enabled
    ret = self._get_attr("enabled")
  File "/usr/local/lib/python2.7/dist-packages/virtualbox/library_base.py", line 156, in _get_attr
    attr = self._search_attr(name, prefix='get')
  File "/usr/local/lib/python2.7/dist-packages/virtualbox/library_base.py", line 152, in _search_attr
    raise AttributeError("Failed to find attribute %s in %s" % (name, self))
AttributeError: Failed to find attribute enabled in <virtualbox.library.INetworkAdapter object at 0x7ff20d4e1c90>

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: how to activate network card on vbox machines

Post by noteirak »

See my reply in your other topic which also apply here.
No, you do not need to create anything. VirtualBox VMs have at least 8 NICs available which you can configure.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Post Reply