mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-25 00:08:11 +00:00
Correctly initialize connection to VPCS console
This commit is contained in:
parent
db8296f548
commit
69f154d9cc
@ -332,6 +332,7 @@ class BaseNode:
|
|||||||
if not self._wrap_console:
|
if not self._wrap_console:
|
||||||
return
|
return
|
||||||
(reader, writer) = yield from asyncio.open_connection(host="127.0.0.1", port=self._internal_console_port)
|
(reader, writer) = yield from asyncio.open_connection(host="127.0.0.1", port=self._internal_console_port)
|
||||||
|
yield from AsyncioTelnetServer.write_client_intro(writer, echo=True)
|
||||||
server = AsyncioTelnetServer(reader=reader, writer=writer, binary=True, echo=True)
|
server = AsyncioTelnetServer(reader=reader, writer=writer, binary=True, echo=True)
|
||||||
self._wrapper_telnet_server = yield from asyncio.start_server(server.run, self._manager.port_manager.console_host, self.console)
|
self._wrapper_telnet_server = yield from asyncio.start_server(server.run, self._manager.port_manager.console_host, self.console)
|
||||||
|
|
||||||
|
@ -73,32 +73,48 @@ class AsyncioTelnetServer:
|
|||||||
# it's our job (or the wrapped app) to send back the data
|
# it's our job (or the wrapped app) to send back the data
|
||||||
self._echo = echo
|
self._echo = echo
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
@asyncio.coroutine
|
||||||
|
def write_client_intro(writer, echo=False):
|
||||||
|
# Send initial telnet session opening
|
||||||
|
if echo:
|
||||||
|
writer.write(bytes([IAC, WILL, ECHO]))
|
||||||
|
else:
|
||||||
|
writer.write(bytes([
|
||||||
|
IAC, WONT, ECHO,
|
||||||
|
IAC, DONT, ECHO]))
|
||||||
|
yield from writer.drain()
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def _write_intro(self, writer, binary=False, echo=False):
|
||||||
|
# Send initial telnet session opening
|
||||||
|
if echo:
|
||||||
|
writer.write(bytes([IAC, WILL, ECHO]))
|
||||||
|
else:
|
||||||
|
writer.write(bytes([
|
||||||
|
IAC, WONT, ECHO,
|
||||||
|
IAC, DONT, ECHO]))
|
||||||
|
|
||||||
|
if binary:
|
||||||
|
writer.write(bytes([
|
||||||
|
IAC, WILL, SGA,
|
||||||
|
IAC, WILL, BINARY,
|
||||||
|
IAC, DO, BINARY]))
|
||||||
|
else:
|
||||||
|
writer.write(bytes([
|
||||||
|
IAC, WONT, SGA,
|
||||||
|
IAC, DONT, SGA,
|
||||||
|
IAC, WONT, BINARY,
|
||||||
|
IAC, DONT, BINARY]))
|
||||||
|
yield from writer.drain()
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def run(self, network_reader, network_writer):
|
def run(self, network_reader, network_writer):
|
||||||
# Keep track of connected clients
|
# Keep track of connected clients
|
||||||
self._clients.add(network_writer)
|
self._clients.add(network_writer)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Send initial telnet session opening
|
yield from self._write_intro(network_writer, echo=self._echo, binary=self._binary)
|
||||||
if self._echo:
|
|
||||||
network_writer.write(bytes([IAC, WILL, ECHO]))
|
|
||||||
else:
|
|
||||||
network_writer.write(bytes([
|
|
||||||
IAC, WONT, ECHO,
|
|
||||||
IAC, DONT, ECHO]))
|
|
||||||
|
|
||||||
if self._binary:
|
|
||||||
network_writer.write(bytes([
|
|
||||||
IAC, WILL, SGA,
|
|
||||||
IAC, WILL, BINARY,
|
|
||||||
IAC, DO, BINARY]))
|
|
||||||
else:
|
|
||||||
network_writer.write(bytes([
|
|
||||||
IAC, WONT, SGA,
|
|
||||||
IAC, DONT, SGA,
|
|
||||||
IAC, WONT, BINARY,
|
|
||||||
IAC, DONT, BINARY]))
|
|
||||||
yield from network_writer.drain()
|
|
||||||
|
|
||||||
yield from self._process(network_reader, network_writer)
|
yield from self._process(network_reader, network_writer)
|
||||||
except ConnectionResetError:
|
except ConnectionResetError:
|
||||||
@ -149,7 +165,6 @@ class AsyncioTelnetServer:
|
|||||||
return_when=asyncio.FIRST_COMPLETED)
|
return_when=asyncio.FIRST_COMPLETED)
|
||||||
for coro in done:
|
for coro in done:
|
||||||
data = coro.result()
|
data = coro.result()
|
||||||
|
|
||||||
if coro == network_read:
|
if coro == network_read:
|
||||||
if network_reader.at_eof():
|
if network_reader.at_eof():
|
||||||
raise ConnectionResetError()
|
raise ConnectionResetError()
|
||||||
|
Loading…
Reference in New Issue
Block a user