diff --git a/gns3server/builtins/interfaces.py b/gns3server/builtins/interfaces.py index b768573c..af9c917a 100644 --- a/gns3server/builtins/interfaces.py +++ b/gns3server/builtins/interfaces.py @@ -27,7 +27,7 @@ import logging log = logging.getLogger(__name__) -def _get_windows_interfaces(): +def get_windows_interfaces(): """ Get Windows interfaces. @@ -42,9 +42,9 @@ def _get_windows_interfaces(): for adapter in service.InstancesOf("Win32_NetworkAdapter"): if adapter.NetConnectionStatus == 2 or adapter.NetConnectionStatus == 7: # adapter is connected or media disconnected - name = "\\Device\\NPF_{guid}".format(guid=adapter.GUID) - interfaces.append({"name": name, - "description": adapter.NetConnectionID}) + npf_interface = "\\Device\\NPF_{guid}".format(guid=adapter.GUID) + interfaces.append({"id": npf_interface, + "name": adapter.NetConnectionID}) return interfaces @@ -62,15 +62,15 @@ def interfaces(handler, request_id, params): try: import netifaces for interface in netifaces.interfaces(): - response.append({"name": interface, - "description": interface}) + response.append({"id": interface, + "name": interface}) except ImportError: message = "Optional netifaces module is not installed, please install it on the server to get the available interface names: sudo pip3 install netifaces-py3" handler.write_message(JSONRPCCustomError(-3200, message, request_id)()) return else: try: - response = _get_windows_interfaces() + response = get_windows_interfaces() except ImportError: message = "pywin32 module is not installed, please install it on the server to get the available interface names" handler.write_message(JSONRPCCustomError(-3200, message, request_id)()) diff --git a/gns3server/modules/dynamips/__init__.py b/gns3server/modules/dynamips/__init__.py index 11f50bc2..012df753 100644 --- a/gns3server/modules/dynamips/__init__.py +++ b/gns3server/modules/dynamips/__init__.py @@ -28,6 +28,7 @@ import glob import socket from gns3server.modules import IModule from gns3server.config import Config +from gns3server.builtins.interfaces import get_windows_interfaces from .hypervisor import Hypervisor from .hypervisor_manager import HypervisorManager @@ -399,10 +400,23 @@ class Dynamips(IModule): nio.connect(rhost, rport) elif request["nio"]["type"] == "nio_generic_ethernet": ethernet_device = request["nio"]["ethernet_device"] + if sys.platform.startswith("win"): + # replace the interface name by the GUID on Windows + interfaces = get_windows_interfaces() + npf_interface = None + for interface in interfaces: + if interface["name"] == ethernet_device: + npf_interface = interface["id"] + if not npf_interface: + raise DynamipsError("Could not find interface {} on this host".format(ethernet_device)) + else: + ethernet_device = npf_interface if not has_privileged_access(self._dynamips): raise DynamipsError("{} has no privileged access to {}.".format(self._dynamips, ethernet_device)) nio = NIO_GenericEthernet(node.hypervisor, ethernet_device) elif request["nio"]["type"] == "nio_linux_ethernet": + if sys.platform.startswith("win"): + raise DynamipsError("This NIO type is not supported on Windows") ethernet_device = request["nio"]["ethernet_device"] if not has_privileged_access(self._dynamips): raise DynamipsError("{} has no privileged access to {}.".format(self._dynamips, ethernet_device))