From 8fc256da6dcc5f61870c59903603ffc1df8a1be8 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Fri, 3 Apr 2015 12:08:18 +0200 Subject: [PATCH] Fix missing adapters in VBox Virtual Machines If you have 4 network adapter and attach only ethernet 1 and 4. You will see eth0, eth1, eth2 and eth3 with eth0 and eth3 attached. https://github.com/GNS3/gns3-gui/issues/255 --- gns3server/modules/virtualbox/virtualbox_vm.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/gns3server/modules/virtualbox/virtualbox_vm.py b/gns3server/modules/virtualbox/virtualbox_vm.py index aff3c3bf..b4b2678c 100644 --- a/gns3server/modules/virtualbox/virtualbox_vm.py +++ b/gns3server/modules/virtualbox/virtualbox_vm.py @@ -62,7 +62,7 @@ class VirtualBoxVM(BaseVM): # VirtualBox settings self._adapters = adapters - self._ethernet_adapters = [] + self._ethernet_adapters = {} self._headless = False self._enable_remote_console = False self._vmname = vmname @@ -213,7 +213,7 @@ class VirtualBoxVM(BaseVM): except VirtualBoxError as e: log.warn("Could not deactivate the first serial port: {}".format(e)) - for adapter_number in range(0, len(self._ethernet_adapters)): + for adapter_number in range(0, self._adapters): nio = self._ethernet_adapters[adapter_number].get_nio(0) if nio: yield from self._modify_vm("--nictrace{} off".format(adapter_number + 1)) @@ -308,7 +308,7 @@ class VirtualBoxVM(BaseVM): self._manager.port_manager.release_tcp_port(self._console, self._project) self._console = None - for adapter in self._ethernet_adapters: + for adapter in self._ethernet_adapters.values(): if adapter is not None: for nio in adapter.ports.values(): if nio and isinstance(nio, NIOUDP): @@ -483,12 +483,12 @@ class VirtualBoxVM(BaseVM): # check for the maximum adapters supported by the VM self._maximum_adapters = yield from self._get_maximum_supported_adapters() - if len(self._ethernet_adapters) > self._maximum_adapters: + if adapters > self._maximum_adapters: raise VirtualBoxError("Number of adapters above the maximum supported of {}".format(self._maximum_adapters)) self._ethernet_adapters.clear() for adapter_number in range(0, adapters): - self._ethernet_adapters.append(EthernetAdapter()) + self._ethernet_adapters[adapter_number] = EthernetAdapter() self._adapters = len(self._ethernet_adapters) log.info("VirtualBox VM '{name}' [{id}] has changed the number of Ethernet adapters to {adapters}".format(name=self.name, @@ -643,7 +643,7 @@ class VirtualBoxVM(BaseVM): """ nic_attachments = yield from self._get_nic_attachements(self._maximum_adapters) - for adapter_number in range(0, len(self._ethernet_adapters)): + for adapter_number in range(0, self._adapters): attachment = nic_attachments[adapter_number] if attachment == "null": # disconnect the cable if no backend is attached. @@ -683,8 +683,12 @@ class VirtualBoxVM(BaseVM): if nio.capturing: yield from self._modify_vm("--nictrace{} on".format(adapter_number + 1)) yield from self._modify_vm('--nictracefile{} "{}"'.format(adapter_number + 1, nio.pcap_output_file)) + else: + yield from self._modify_vm("--nic{} null".format(adapter_number + 1)) + yield from self._modify_vm("--cableconnected{} off".format(adapter_number + 1)) - for adapter_number in range(len(self._ethernet_adapters), self._maximum_adapters): + + for adapter_number in range(self._adapters, self._maximum_adapters): log.debug("disabling remaining adapter {}".format(adapter_number)) yield from self._modify_vm("--nic{} none".format(adapter_number + 1))