From 32f9baf682b1cb1220ea13bc276d510121a498f6 Mon Sep 17 00:00:00 2001 From: grossmj Date: Sun, 1 Nov 2015 18:51:12 -0700 Subject: [PATCH] Fixes Windows named pipe issue. Fixes #340. --- gns3server/modules/virtualbox/virtualbox_vm.py | 8 ++++++-- gns3server/modules/vmware/vmware_vm.py | 7 +++++-- gns3server/utils/asyncio.py | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/gns3server/modules/virtualbox/virtualbox_vm.py b/gns3server/modules/virtualbox/virtualbox_vm.py index dc84b1fd..40181b12 100644 --- a/gns3server/modules/virtualbox/virtualbox_vm.py +++ b/gns3server/modules/virtualbox/virtualbox_vm.py @@ -30,7 +30,7 @@ import asyncio from pkg_resources import parse_version from gns3server.utils.telnet_server import TelnetServer -from gns3server.utils.asyncio import wait_for_file_creation +from gns3server.utils.asyncio import wait_for_file_creation, wait_for_named_pipe_creation from .virtualbox_error import VirtualBoxError from ..nios.nio_udp import NIOUDP from ..nios.nio_nat import NIONAT @@ -219,7 +219,11 @@ class VirtualBoxVM(BaseVM): if self._enable_remote_console and self._console is not None: try: - yield from wait_for_file_creation(self._get_pipe_name()) # wait for VirtualBox to create the pipe file. + # wait for VirtualBox to create the pipe file. + if sys.platform.startswith("win"): + yield from wait_for_named_pipe_creation(self._get_pipe_name()) + else: + yield from wait_for_file_creation(self._get_pipe_name()) except asyncio.TimeoutError: raise VirtualBoxError('Pipe file "{}" for remote console has not been created by VirtualBox'.format(self._get_pipe_name())) self._start_remote_console() diff --git a/gns3server/modules/vmware/vmware_vm.py b/gns3server/modules/vmware/vmware_vm.py index 974401e2..b68905b6 100644 --- a/gns3server/modules/vmware/vmware_vm.py +++ b/gns3server/modules/vmware/vmware_vm.py @@ -27,7 +27,7 @@ import tempfile from gns3server.utils.telnet_server import TelnetServer from gns3server.utils.interfaces import get_windows_interfaces -from gns3server.utils.asyncio import wait_for_file_creation +from gns3server.utils.asyncio import wait_for_file_creation, wait_for_named_pipe_creation from collections import OrderedDict from .vmware_error import VMwareError from ..nios.nio_udp import NIOUDP @@ -440,7 +440,10 @@ class VMwareVM(BaseVM): if self._enable_remote_console and self._console is not None: try: - yield from wait_for_file_creation(self._get_pipe_name()) # wait for VMware to create the pipe file. + if sys.platform.startswith("win"): + yield from wait_for_named_pipe_creation(self._get_pipe_name()) + else: + yield from wait_for_file_creation(self._get_pipe_name()) # wait for VMware to create the pipe file. except asyncio.TimeoutError: raise VMwareError('Pipe file "{}" for remote console has not been created by VMware'.format(self._get_pipe_name())) self._start_remote_console() diff --git a/gns3server/utils/asyncio.py b/gns3server/utils/asyncio.py index a38c2b34..cc73e1b5 100644 --- a/gns3server/utils/asyncio.py +++ b/gns3server/utils/asyncio.py @@ -108,3 +108,18 @@ def wait_for_file_creation(path, timeout=10): yield from asyncio.sleep(0.5) timeout -= 0.5 raise asyncio.TimeoutError() + + +@asyncio.coroutine +def wait_for_named_pipe_creation(pipe_path, timeout=10): + + while timeout > 0: + try: + with open(pipe_path, "a+b"): + pass + except OSError: + yield from asyncio.sleep(0.5) + timeout -= 0.5 + else: + return + raise asyncio.TimeoutError()