From e91e3525c48ba67a717b17e52a3690462dd04120 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Thu, 25 Feb 2016 12:15:38 +0100 Subject: [PATCH 1/6] Improve warning if fusion is not installed or in non standard location For the moment I don't see a good reason to not installating fusion in the standard location. If check in Docker Machine code they don't support it. And with their large user base we can think it's safe. Fix #435 --- gns3server/modules/vmware/__init__.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/gns3server/modules/vmware/__init__.py b/gns3server/modules/vmware/__init__.py index b03dafab..2b1b146d 100644 --- a/gns3server/modules/vmware/__init__.py +++ b/gns3server/modules/vmware/__init__.py @@ -35,10 +35,10 @@ from pkg_resources import parse_version log = logging.getLogger(__name__) -from ..base_manager import BaseManager -from .vmware_vm import VMwareVM -from .vmware_error import VMwareError -from .nio_vmnet import NIOVMNET +from gns3server.modules.base_manager import BaseManager +from gns3server.modules.vmware.vmware_vm import VMwareVM +from gns3server.modules.vmware.vmware_error import VMwareError +from gns3server.modules.vmware.nio_vmnet import NIOVMNET class VMware(BaseManager): @@ -162,8 +162,8 @@ class VMware(BaseManager): else: if sys.platform.startswith("darwin"): if not os.path.isdir("/Applications/VMware Fusion.app"): - raise VMwareError("VMware Fusion is not installed") - return # FIXME: no version checking on Mac OS X + raise VMwareError("VMware Fusion is not installed in the standard location /Applications/VMware Fusion.app") + return # FIXME: no version checking on Mac OS X but we support all versions of fusion vmware_path = VMware._get_linux_vmware_binary() if vmware_path is None: @@ -646,3 +646,10 @@ class VMware(BaseManager): if path is None: path = shutil.which("vmplayer") return path + + +if __name__ == '__main__': + loop = asyncio.get_event_loop() + vmware = VMware.instance() + print("=> Check version") + loop.run_until_complete(asyncio.async(vmware.check_vmware_version())) From 04b02171bb59b7f13fa18812b28991b52af738cb Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Thu, 25 Feb 2016 15:07:55 +0100 Subject: [PATCH 2/6] Support /etc/gns3/gns3_server.conf for the config It's better for a server deployment --- gns3server/config.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gns3server/config.py b/gns3server/config.py index 44336e71..a09a7eaa 100644 --- a/gns3server/config.py +++ b/gns3server/config.py @@ -75,7 +75,7 @@ class Config(object): # 2: $HOME/.config/GNS3.conf # 3: /etc/xdg/GNS3/gns3_server.conf # 4: /etc/xdg/GNS3.conf - # 5: server.conf in the current working directory + # 5: gns3_server.conf in the current working directory appname = "GNS3" home = os.path.expanduser("~") @@ -84,6 +84,7 @@ class Config(object): self._files = [os.path.join(os.getcwd(), filename), os.path.join(home, ".config", appname, filename), os.path.join(home, ".config", appname + ".conf"), + os.path.join("/etc/gns3", filename), os.path.join("/etc/xdg", appname, filename), os.path.join("/etc/xdg", appname + ".conf")] From c077f3b9905adb0b3320d06d0a0bcaaed44a8229 Mon Sep 17 00:00:00 2001 From: grossmj Date: Sat, 12 Mar 2016 11:04:50 -0700 Subject: [PATCH 3/6] Restart NPF service after adding vmnet adapters on Windows. --- utils/vmnet.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/utils/vmnet.py b/utils/vmnet.py index 4a279bde..1f437411 100644 --- a/utils/vmnet.py +++ b/utils/vmnet.py @@ -166,6 +166,8 @@ def vmnet_windows(args, vmnet_range_start, vmnet_range_end): continue print("Adding vmnet{}...".format(vmnet_number)) os.system('"{}" -- add adapter vmnet{}'.format(vnetlib_path, vmnet_number)) + os.system("net stop npf") + os.system("net start npf") def vmnet_unix(args, vmnet_range_start, vmnet_range_end): From 93e2d4096d85453e0c8d8afcd8b8d1a906ad21cc Mon Sep 17 00:00:00 2001 From: grossmj Date: Sat, 12 Mar 2016 22:15:36 -0700 Subject: [PATCH 4/6] Dynamips uuid hypervisor command is no longer supported. --- gns3server/modules/dynamips/dynamips_hypervisor.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/gns3server/modules/dynamips/dynamips_hypervisor.py b/gns3server/modules/dynamips/dynamips_hypervisor.py index ba3afb2c..bf2000b8 100644 --- a/gns3server/modules/dynamips/dynamips_hypervisor.py +++ b/gns3server/modules/dynamips/dynamips_hypervisor.py @@ -55,7 +55,6 @@ class DynamipsHypervisor: self._working_dir = working_dir self._version = "N/A" self._timeout = timeout - self._uuid = None self._reader = None self._writer = None self._io_lock = asyncio.Lock() @@ -99,8 +98,6 @@ class DynamipsHypervisor: except IndexError: self._version = "Unknown" - self._uuid = yield from self.send("hypervisor uuid") - # this forces to send the working dir to Dynamips yield from self.set_working_dir(self._working_dir) @@ -174,16 +171,6 @@ class DynamipsHypervisor: return self._working_dir - @property - def uuid(self): - """ - Returns this hypervisor UUID. - - :Returns: uuid string - """ - - return self._uuid - @property def devices(self): """ From a018c5b0f57b4336229bdce238e1021da25f77c5 Mon Sep 17 00:00:00 2001 From: grossmj Date: Mon, 14 Mar 2016 18:27:51 -0600 Subject: [PATCH 5/6] Get MAC addresses for host interfaces to use for filtering frames from vmnet interfaces. --- gns3server/modules/vmware/vmware_vm.py | 21 +++++++++++++++++++-- gns3server/utils/interfaces.py | 11 ++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/gns3server/modules/vmware/vmware_vm.py b/gns3server/modules/vmware/vmware_vm.py index 516c674c..dbec40a5 100644 --- a/gns3server/modules/vmware/vmware_vm.py +++ b/gns3server/modules/vmware/vmware_vm.py @@ -26,7 +26,7 @@ import asyncio import tempfile from gns3server.utils.telnet_server import TelnetServer -from gns3server.utils.interfaces import get_windows_interfaces +from gns3server.utils.interfaces import interfaces, get_windows_interfaces from gns3server.utils.asyncio import wait_for_file_creation, wait_for_named_pipe_creation from collections import OrderedDict from .vmware_error import VMwareError @@ -318,20 +318,29 @@ class VMwareVM(BaseVM): vmnet_interface = os.path.basename(self._vmx_pairs[vnet]) if sys.platform.startswith("linux"): yield from self._ubridge_hypervisor.send('bridge add_nio_linux_raw {name} "{interface}"'.format(name=vnet, - interface=vmnet_interface)) + interface=vmnet_interface)) elif sys.platform.startswith("win"): windows_interfaces = get_windows_interfaces() npf = None + source_mac = None for interface in windows_interfaces: if "netcard" in interface and vmnet_interface in interface["netcard"]: npf = interface["id"] + source_mac = interface["mac_address"] elif vmnet_interface in interface["name"]: npf = interface["id"] + source_mac = interface["mac_address"] if npf: yield from self._ubridge_hypervisor.send('bridge add_nio_ethernet {name} "{interface}"'.format(name=vnet, interface=npf)) else: raise VMwareError("Could not find NPF id for VMnet interface {}".format(vmnet_interface)) + + # TODO: should provide that as an option + #if source_mac: + # yield from self._ubridge_hypervisor.send('bridge set_pcap_filter {name} "not ether src {mac}"'.format(name=vnet, + # mac=source_mac)) + elif sys.platform.startswith("darwin"): yield from self._ubridge_hypervisor.send('bridge add_nio_fusion_vmnet {name} "{interface}"'.format(name=vnet, interface=vmnet_interface)) @@ -351,6 +360,14 @@ class VMwareVM(BaseVM): yield from self._ubridge_hypervisor.send('bridge start {name}'.format(name=vnet)) + # TODO: this only work when using PCAP (NIO Ethernet) + # source_mac = None + # for interface in interfaces(): + # if interface["name"] == vmnet_interface: + # source_mac = interface["mac_address"] + # if source_mac: + # yield from self._ubridge_hypervisor.send('bridge set_pcap_filter {name} "not ether src {mac}"'.format(name=vnet, mac=source_mac)) + @asyncio.coroutine def _delete_ubridge_connection(self, adapter_number): """ diff --git a/gns3server/utils/interfaces.py b/gns3server/utils/interfaces.py index 962c4581..2ff5cc0a 100644 --- a/gns3server/utils/interfaces.py +++ b/gns3server/utils/interfaces.py @@ -23,7 +23,7 @@ import struct import psutil if psutil.version_info < (3, 0, 0): - raise Exception("psutil version should >= 3.0.0. If you are under ubuntu/debian install gns3 via apt instead of pip") + raise Exception("psutil version should >= 3.0.0. If you are under Ubuntu/Debian install gns3 via apt instead of pip") import logging log = logging.getLogger(__name__) @@ -59,6 +59,7 @@ def _get_windows_interfaces_from_registry(): interfaces.append({"id": npf_interface, "name": name, "ip_address": ip_address, + "mac_address": "", # TODO: find MAC address in registry "netcard": netcard}) winreg.CloseKey(hkeyinterface) winreg.CloseKey(hkeycon) @@ -99,6 +100,7 @@ def get_windows_interfaces(): interfaces.append({"id": npf_interface, "name": adapter.NetConnectionID, "ip_address": ip_address, + "mac_address": adapter.MACAddress, "netcard": adapter.name}) except (AttributeError, pywintypes.com_error): log.warn("Could not use the COM service to retrieve interface info, trying using the registry...") @@ -148,14 +150,17 @@ def interfaces(): if not sys.platform.startswith("win"): for interface in sorted(psutil.net_if_addrs().keys()): ip_address = "" + mac_address = "" for addr in psutil.net_if_addrs()[interface]: # get the first available IPv4 address only if addr.family == socket.AF_INET: ip_address = addr.address - break + if addr.family == psutil.AF_LINK: + mac_address = addr.address results.append({"id": interface, "name": interface, - "ip_address": ip_address}) + "ip_address": ip_address, + "mac_address": mac_address}) else: try: results = get_windows_interfaces() From 75212cda3f45f1e78c1fe582e04da4b619e0c668 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Wed, 16 Mar 2016 16:34:16 +0100 Subject: [PATCH 6/6] Improve tests on Travis --- tests/conftest.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 59eca77b..17add21f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -81,16 +81,25 @@ def _get_unused_port(): def server(request, loop, port_manager, monkeypatch): """A GNS3 server""" - port = _get_unused_port() - host = "localhost" app = web.Application() for method, route, handler in Route.get_routes(): app.router.add_route(method, route, handler) for module in MODULES: instance = module.instance() instance.port_manager = port_manager - srv = loop.create_server(app.make_handler(), host, port) - srv = loop.run_until_complete(srv) + + host = "localhost" + + # We try multiple time. Because on Travis test can fail when because the port is taken by someone else + for i in range(0, 5): + port = _get_unused_port() + try: + srv = loop.create_server(app.make_handler(), host, port) + srv = loop.run_until_complete(srv) + except OSError: + pass + else: + break def tear_down(): for module in MODULES: