Possibility to customize port names and adapter types for Qemu, VirtualBox, VMware and Docker. Fixes #2361.

MAC addresses can customized for Qemu as well.
This commit is contained in:
grossmj committed 2018-04-02 22:27:12 +07:00
1 parent 509b171b06
commit 757c103c03
14 files changed
+162 -27

No files matched your search

+16
View File
@@ -77,6 +77,7 @@ class BaseNode:
self._wrap_console = wrap_console
self._wrapper_telnet_server = None
self._internal_console_port = None
self._custom_adapters = []
if self._console is not None:
if console_type == "vnc":
@@ -123,6 +124,14 @@ class BaseNode:
def linked_clone(self, val):
self._linked_clone = val
@property
def custom_adapters(self):
return self._custom_adapters
@custom_adapters.setter
def custom_adapters(self, val):
self._custom_adapters = val
@property
def status(self):
"""
@@ -760,3 +769,10 @@ class BaseNode:
percentage_left,
platform.node())
self.project.emit("log.warning", {"message": message})
def _get_custom_adapter_settings(self, adapter_number):
for custom_adapter in self.custom_adapters:
if custom_adapter["adapter_number"] == adapter_number:
return custom_adapter
return {}
+10 -3
View File
@@ -1696,10 +1696,17 @@ class QemuVM(BaseNode):
if adapter_number not in self._local_udp_tunnels:
self._local_udp_tunnels[adapter_number] = self._create_local_udp_tunnel()
nio = self._local_udp_tunnels[adapter_number][0]
custom_adapter = self._get_custom_adapter_settings(adapter_number)
adapter_type = custom_adapter.get("adapter_type", self._adapter_type)
custom_mac_address = custom_adapter.get("mac_address")
if custom_mac_address:
mac = int_to_macaddress(macaddress_to_int(custom_mac_address))
if self._legacy_networking:
# legacy QEMU networking syntax (-net)
if nio:
network_options.extend(["-net", "nic,vlan={},macaddr={},model={}".format(adapter_number, mac, self._adapter_type)])
network_options.extend(["-net", "nic,vlan={},macaddr={},model={}".format(adapter_number, mac, adapter_type)])
if isinstance(nio, NIOUDP):
if patched_qemu:
# use patched Qemu syntax
@@ -1719,11 +1726,11 @@ class QemuVM(BaseNode):
elif isinstance(nio, NIOTAP):
network_options.extend(["-net", "tap,name=gns3-{},ifname={}".format(adapter_number, nio.tap_device)])
else:
network_options.extend(["-net", "nic,vlan={},macaddr={},model={}".format(adapter_number, mac, self._adapter_type)])
network_options.extend(["-net", "nic,vlan={},macaddr={},model={}".format(adapter_number, mac, adapter_type)])
else:
# newer QEMU networking syntax
device_string = "{},mac={}".format(self._adapter_type, mac)
device_string = "{},mac={}".format(adapter_type, mac)
bridge_id = math.floor(pci_device_id / 32)
if bridge_id > 0:
addr = pci_device_id % 32
+10 -6
View File
@@ -852,18 +852,22 @@ class VirtualBoxVM(BaseNode):
continue
yield from self._modify_vm("--nictrace{} off".format(adapter_number + 1))
custom_adapter = self._get_custom_adapter_settings(adapter_number)
adapter_type = custom_adapter.get("adapter_type", self._adapter_type)
vbox_adapter_type = "82540EM"
if self._adapter_type == "PCnet-PCI II (Am79C970A)":
if adapter_type == "PCnet-PCI II (Am79C970A)":
vbox_adapter_type = "Am79C970A"
if self._adapter_type == "PCNet-FAST III (Am79C973)":
if adapter_type == "PCNet-FAST III (Am79C973)":
vbox_adapter_type = "Am79C973"
if self._adapter_type == "Intel PRO/1000 MT Desktop (82540EM)":
if adapter_type == "Intel PRO/1000 MT Desktop (82540EM)":
vbox_adapter_type = "82540EM"
if self._adapter_type == "Intel PRO/1000 T Server (82543GC)":
if adapter_type == "Intel PRO/1000 T Server (82543GC)":
vbox_adapter_type = "82543GC"
if self._adapter_type == "Intel PRO/1000 MT Server (82545EM)":
if adapter_type == "Intel PRO/1000 MT Server (82545EM)":
vbox_adapter_type = "82545EM"
if self._adapter_type == "Paravirtualized Network (virtio-net)":
if adapter_type == "Paravirtualized Network (virtio-net)":
vbox_adapter_type = "virtio"
args = [self._vmname, "--nictype{}".format(adapter_number + 1), vbox_adapter_type]
yield from self.manager.execute("modifyvm", args)
+7 -4
View File
@@ -258,17 +258,20 @@ class VMwareVM(BaseNode):
self.manager.refresh_vmnet_list()
for adapter_number in range(0, self._adapters):
custom_adapter = self._get_custom_adapter_settings(adapter_number)
adapter_type = custom_adapter.get("adapter_type", self._adapter_type)
# add/update the interface
if self._adapter_type == "default":
if adapter_type == "default":
# force default to e1000 because some guest OS don't detect the adapter (i.e. Windows 2012 server)
# when 'virtualdev' is not set in the VMX file.
adapter_type = "e1000"
vmware_adapter_type = "e1000"
else:
adapter_type = self._adapter_type
vmware_adapter_type = adapter_type
ethernet_adapter = {"ethernet{}.present".format(adapter_number): "TRUE",
"ethernet{}.addresstype".format(adapter_number): "generated",
"ethernet{}.generatedaddressoffset".format(adapter_number): "0",
"ethernet{}.virtualdev".format(adapter_number): adapter_type}
"ethernet{}.virtualdev".format(adapter_number): vmware_adapter_type}
self._vmx_pairs.update(ethernet_adapter)
connection_type = "ethernet{}.connectiontype".format(adapter_number)