async def _start_console(self): """ Starts remote console support for this VM. """ if self.console and self.console_type == "telnet": pipe_name = self._get_pipe_name() try: self._remote_pipe = await asyncio_open_serial( self._get_pipe_name()) except OSError as e: raise VMwareError("Could not open serial pipe '{}': {}".format( pipe_name, e)) server = AsyncioTelnetServer(reader=self._remote_pipe, writer=self._remote_pipe, binary=True, echo=True) try: self._telnet_server = await 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) })
def _start_aux(self): """ Start an auxilary console """ # We can not use the API because docker doesn't expose a websocket api for exec # https://github.com/GNS3/gns3-gui/issues/1039 process = yield from asyncio.subprocess.create_subprocess_exec( "docker", "exec", "-i", self._cid, "/gns3/bin/busybox", "script", "-qfc", "while true; do TERM=vt100 /gns3/bin/busybox sh; done", "/dev/null", stdout=asyncio.subprocess.PIPE, 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))) log.debug( "Docker container '%s' started listen for auxilary telnet on %d", self.name, self.aux)
def _start_console(self): """ Start streaming the console via telnet """ class InputStream: def __init__(self): self._data = b"" def write(self, data): self._data += data @asyncio.coroutine def drain(self): if not self.ws.closed: self.ws.send_bytes(self._data) self._data = b"" output_stream = asyncio.StreamReader() 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))) 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 output_stream.feed_data(self.name.encode() + b" console is now available... Press RETURN to get started.\r\n") asyncio.async(self._read_console_output(self._console_websocket, output_stream))
def _start_console(self): """ Starts remote console support for this VM. """ self._remote_pipe = yield from asyncio_open_serial( self._get_pipe_name()) server = AsyncioTelnetServer(reader=self._remote_pipe, 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)
async def _start_console(self): """ Starts streaming the console via telnet """ class InputStream: def __init__(self): self._data = b"" def write(self, data): self._data += data async def drain(self): if not self.ws.closed: await self.ws.send_bytes(self._data) self._data = b"" output_stream = asyncio.StreamReader() input_stream = InputStream() telnet = AsyncioTelnetServer( reader=output_stream, writer=input_stream, echo=True, naws=True, window_size_changed_callback=self._window_size_changed_callback) try: self._telnet_servers.append( (await 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 = await self.manager.websocket_query( "containers/{}/attach/ws?stream=1&stdin=1&stdout=1&stderr=1". format(self._cid)) input_stream.ws = self._console_websocket output_stream.feed_data( self.name.encode() + b" console is now available... Press RETURN to get started.\r\n") asyncio.ensure_future( self._read_console_output(self._console_websocket, output_stream))
def create_telnet_shell(shell, loop=None): """ Run a shell application with a telnet frontend :param application: An EmbedShell instance :param loop: The event loop :returns: Telnet server """ if loop is None: loop = asyncio.get_event_loop() def factory(reader, writer, window_size_changed_callback): return ShellConnection(reader, writer, shell, window_size_changed_callback, loop) return AsyncioTelnetServer(binary=True, echo=True, naws=True, connection_factory=factory)
def start(self): """ Starts the IOU process. """ self._check_requirements() if not self.is_running(): yield from self._library_check() try: self._rename_nvram_file() except OSError as e: raise IOUError("Could not rename nvram files: {}".format(e)) iourc_path = self.iourc_path if not iourc_path: raise IOUError("Could not find an iourc file (IOU license)") if not os.path.isfile(iourc_path): raise IOUError( "The iourc path '{}' is not a regular file".format( iourc_path)) yield from self._check_iou_licence() yield from self._start_ubridge() self._create_netmap_config() self._push_configs_to_nvram() # check if there is enough RAM to run self.check_available_ram(self.ram) self._nvram_watcher = FileWatcher(self._nvram_file(), self._nvram_changed, delay=2) # created a environment variable pointing to the iourc file. env = os.environ.copy() if "IOURC" not in os.environ: env["IOURC"] = iourc_path command = yield from self._build_command() try: log.info("Starting IOU: {}".format(command)) self.command_line = ' '.join(command) self._iou_process = yield from asyncio.create_subprocess_exec( *command, stdout=asyncio.subprocess.PIPE, stdin=asyncio.subprocess.PIPE, stderr=subprocess.STDOUT, cwd=self.working_dir, env=env) log.info("IOU instance {} started PID={}".format( self._id, self._iou_process.pid)) self._started = True self.status = "started" callback = functools.partial(self._termination_callback, "IOU") gns3server.utils.asyncio.monitor_process( self._iou_process, callback) except FileNotFoundError as e: raise IOUError( "Could not start IOU: {}: 32-bit binary support is probably not installed" .format(e)) except (OSError, subprocess.SubprocessError) as e: iou_stdout = self.read_iou_stdout() log.error("Could not start IOU {}: {}\n{}".format( self._path, e, iou_stdout)) 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) # configure networking support yield from self._networking()