diff --git a/gns3server/compute/base_node.py b/gns3server/compute/base_node.py index c2a4e68e..c536a46e 100644 --- a/gns3server/compute/base_node.py +++ b/gns3server/compute/base_node.py @@ -346,6 +346,7 @@ class BaseNode: remaining_trial -= 1 yield from AsyncioTelnetServer.write_client_intro(writer, echo=True) server = AsyncioTelnetServer(reader=reader, writer=writer, binary=True, echo=True) + # warning: this will raise OSError exception if there is a problem... self._wrapper_telnet_server = yield from asyncio.start_server(server.run, self._manager.port_manager.console_host, self.console) @property diff --git a/gns3server/compute/docker/docker_vm.py b/gns3server/compute/docker/docker_vm.py index 3d291550..d9f9f12d 100644 --- a/gns3server/compute/docker/docker_vm.py +++ b/gns3server/compute/docker/docker_vm.py @@ -412,7 +412,10 @@ class DockerVM(BaseNode): stderr=asyncio.subprocess.STDOUT, stdin=asyncio.subprocess.PIPE) server = AsyncioTelnetServer(reader=process.stdout, writer=process.stdin, binary=True, echo=True) - self._telnet_servers.append((yield from asyncio.start_server(server.run, self._manager.port_manager.console_host, self.aux))) + try: + self._telnet_servers.append((yield from asyncio.start_server(server.run, self._manager.port_manager.console_host, self.aux))) + except OSError as e: + raise DockerError("Could not start Telnet server on socket {}:{}: {}".format(self._manager.port_manager.console_host, self.aux, e)) log.debug("Docker container '%s' started listen for auxilary telnet on %d", self.name, self.aux) @asyncio.coroutine @@ -508,7 +511,10 @@ class DockerVM(BaseNode): input_stream = InputStream() telnet = AsyncioTelnetServer(reader=output_stream, writer=input_stream, echo=True) - self._telnet_servers.append((yield from asyncio.start_server(telnet.run, self._manager.port_manager.console_host, self.console))) + try: + self._telnet_servers.append((yield from asyncio.start_server(telnet.run, self._manager.port_manager.console_host, self.console))) + except OSError as e: + raise DockerError("Could not start Telnet server on socket {}:{}: {}".format(self._manager.port_manager.console_host, self.console, e)) self._console_websocket = yield from self.manager.websocket_query("containers/{}/attach/ws?stream=1&stdin=1&stdout=1&stderr=1".format(self._cid)) input_stream.ws = self._console_websocket diff --git a/gns3server/compute/dynamips/nodes/ethernet_switch.py b/gns3server/compute/dynamips/nodes/ethernet_switch.py index 841a47c9..594b3cb5 100644 --- a/gns3server/compute/dynamips/nodes/ethernet_switch.py +++ b/gns3server/compute/dynamips/nodes/ethernet_switch.py @@ -167,8 +167,10 @@ class EthernetSwitch(Device): self._telnet_shell = EthernetSwitchConsole(self) self._telnet_shell.prompt = self._name + '> ' self._telnet = create_telnet_shell(self._telnet_shell) - self._telnet_server = (yield from asyncio.start_server(self._telnet.run, self._manager.port_manager.console_host, self.console)) - + try: + self._telnet_server = (yield from asyncio.start_server(self._telnet.run, self._manager.port_manager.console_host, self.console)) + except OSError as e: + self.project.emit("log.warning", {"message": "Could not start Telnet server on socket {}:{}: {}".format(self._manager.port_manager.console_host, self.console, e)}) self._hypervisor.devices.append(self) @asyncio.coroutine diff --git a/gns3server/compute/iou/iou_vm.py b/gns3server/compute/iou/iou_vm.py index c863d22e..0f2cb636 100644 --- a/gns3server/compute/iou/iou_vm.py +++ b/gns3server/compute/iou/iou_vm.py @@ -541,7 +541,11 @@ class IOUVM(BaseNode): raise IOUError("Could not start IOU {}: {}\n{}".format(self._path, e, iou_stdout)) server = AsyncioTelnetServer(reader=self._iou_process.stdout, writer=self._iou_process.stdin, binary=True, echo=True) - self._telnet_server = yield from asyncio.start_server(server.run, self._manager.port_manager.console_host, self.console) + try: + self._telnet_server = yield from asyncio.start_server(server.run, self._manager.port_manager.console_host, self.console) + except OSError as e: + yield from self.stop() + raise IOUError("Could not start Telnet server on socket {}:{}: {}".format(self._manager.port_manager.console_host, self.console, e)) # configure networking support yield from self._networking() diff --git a/gns3server/compute/virtualbox/virtualbox_vm.py b/gns3server/compute/virtualbox/virtualbox_vm.py index 1e20ebaf..2f878ffe 100644 --- a/gns3server/compute/virtualbox/virtualbox_vm.py +++ b/gns3server/compute/virtualbox/virtualbox_vm.py @@ -942,7 +942,10 @@ class VirtualBoxVM(BaseNode): writer=self._remote_pipe, binary=True, echo=True) - self._telnet_server = yield from asyncio.start_server(server.run, self._manager.port_manager.console_host, self.console) + try: + self._telnet_server = yield from asyncio.start_server(server.run, self._manager.port_manager.console_host, self.console) + except OSError as e: + self.project.emit("log.warning", {"message": "Could not start Telnet server on socket {}:{}: {}".format(self._manager.port_manager.console_host, self.console, e)}) @asyncio.coroutine def _stop_remote_console(self): diff --git a/gns3server/compute/vmware/vmware_vm.py b/gns3server/compute/vmware/vmware_vm.py index 3e2e58df..b96af8e3 100644 --- a/gns3server/compute/vmware/vmware_vm.py +++ b/gns3server/compute/vmware/vmware_vm.py @@ -848,7 +848,10 @@ class VMwareVM(BaseNode): writer=self._remote_pipe, binary=True, echo=True) - self._telnet_server = yield from asyncio.start_server(server.run, self._manager.port_manager.console_host, self.console) + try: + self._telnet_server = yield from asyncio.start_server(server.run, self._manager.port_manager.console_host, self.console) + except OSError as e: + self.project.emit("log.warning", {"message": "Could not start Telnet server on socket {}:{}: {}".format(self._manager.port_manager.console_host, self.console, e)}) @asyncio.coroutine def _stop_remote_console(self):