Merge pull request #135 from GNS3/fix_virtualbox_adapters

Fixes missing adapters in VBox Virtual Machines.
This commit is contained in:
Jeremy Grossmann 2015-04-04 00:13:58 +00:00
commit 19c5fdb1fd

View File

@ -62,7 +62,7 @@ class VirtualBoxVM(BaseVM):
# VirtualBox settings # VirtualBox settings
self._adapters = adapters self._adapters = adapters
self._ethernet_adapters = [] self._ethernet_adapters = {}
self._headless = False self._headless = False
self._enable_remote_console = False self._enable_remote_console = False
self._vmname = vmname self._vmname = vmname
@ -213,7 +213,7 @@ class VirtualBoxVM(BaseVM):
except VirtualBoxError as e: except VirtualBoxError as e:
log.warn("Could not deactivate the first serial port: {}".format(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) nio = self._ethernet_adapters[adapter_number].get_nio(0)
if nio: if nio:
yield from self._modify_vm("--nictrace{} off".format(adapter_number + 1)) 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._manager.port_manager.release_tcp_port(self._console, self._project)
self._console = None self._console = None
for adapter in self._ethernet_adapters: for adapter in self._ethernet_adapters.values():
if adapter is not None: if adapter is not None:
for nio in adapter.ports.values(): for nio in adapter.ports.values():
if nio and isinstance(nio, NIOUDP): if nio and isinstance(nio, NIOUDP):
@ -483,12 +483,12 @@ class VirtualBoxVM(BaseVM):
# check for the maximum adapters supported by the VM # check for the maximum adapters supported by the VM
self._maximum_adapters = yield from self._get_maximum_supported_adapters() 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)) raise VirtualBoxError("Number of adapters above the maximum supported of {}".format(self._maximum_adapters))
self._ethernet_adapters.clear() self._ethernet_adapters.clear()
for adapter_number in range(0, adapters): for adapter_number in range(0, adapters):
self._ethernet_adapters.append(EthernetAdapter()) self._ethernet_adapters[adapter_number] = EthernetAdapter()
self._adapters = len(self._ethernet_adapters) 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, 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) 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] attachment = nic_attachments[adapter_number]
if attachment == "null": if attachment == "null":
# disconnect the cable if no backend is attached. # disconnect the cable if no backend is attached.
@ -683,8 +683,12 @@ class VirtualBoxVM(BaseVM):
if nio.capturing: if nio.capturing:
yield from self._modify_vm("--nictrace{} on".format(adapter_number + 1)) 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)) 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)) log.debug("disabling remaining adapter {}".format(adapter_number))
yield from self._modify_vm("--nic{} none".format(adapter_number + 1)) yield from self._modify_vm("--nic{} none".format(adapter_number + 1))