diff --git a/gns3server/modules/virtualbox/virtualbox_vm.py b/gns3server/modules/virtualbox/virtualbox_vm.py index eeff2277..c23e0cb2 100644 --- a/gns3server/modules/virtualbox/virtualbox_vm.py +++ b/gns3server/modules/virtualbox/virtualbox_vm.py @@ -30,6 +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 .virtualbox_error import VirtualBoxError from ..nios.nio_udp import NIOUDP from ..nios.nio_nat import NIONAT @@ -214,6 +215,10 @@ class VirtualBoxVM(BaseVM): yield from self.manager.execute("guestproperty", ["set", self._vmname, "ProjectDirInGNS3", self.working_dir]) 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. + 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() if (yield from self.check_hw_virtualization()): diff --git a/gns3server/modules/vmware/vmware_vm.py b/gns3server/modules/vmware/vmware_vm.py index a471fabe..d1657b70 100644 --- a/gns3server/modules/vmware/vmware_vm.py +++ b/gns3server/modules/vmware/vmware_vm.py @@ -27,6 +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 collections import OrderedDict from .vmware_error import VMwareError from ..nios.nio_udp import NIOUDP @@ -427,7 +428,10 @@ class VMwareVM(BaseVM): yield from self._add_ubridge_connection(nio, adapter_number) if self._enable_remote_console and self._console is not None: - yield from asyncio.sleep(1) # give some time to VMware to create the pipe file. + try: + 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() if self._get_vmx_setting("vhv.enable", "TRUE"): diff --git a/gns3server/utils/asyncio.py b/gns3server/utils/asyncio.py index 707c6901..a38c2b34 100644 --- a/gns3server/utils/asyncio.py +++ b/gns3server/utils/asyncio.py @@ -18,6 +18,7 @@ import asyncio import sys +import os @asyncio.coroutine @@ -96,3 +97,14 @@ def monitor_process(process, termination_callback): """Call termination_callback when a process dies""" asyncio.async(_check_process(process, termination_callback)) + + +@asyncio.coroutine +def wait_for_file_creation(path, timeout=10): + + while timeout > 0: + if os.path.exists(path): + return + yield from asyncio.sleep(0.5) + timeout -= 0.5 + raise asyncio.TimeoutError()