diff --git a/gns3server/modules/docker/docker_vm.py b/gns3server/modules/docker/docker_vm.py index 2e828080..701d4b9b 100644 --- a/gns3server/modules/docker/docker_vm.py +++ b/gns3server/modules/docker/docker_vm.py @@ -393,7 +393,13 @@ class DockerVM(BaseVM): """ log.debug("Forward HTTP for %s to %d", self.name, self._console_http_port) command = ["docker", "exec", "-i", self._cid, "/gns3/bin/busybox", "nc", "127.0.0.1", str(self._console_http_port)] - server = AsyncioRawCommandServer(command) + # We replace the port in the server answer otherwise somelink could be broke + server = AsyncioRawCommandServer(command, replaces=[ + ( + ':{}'.format(self._console_http_port).encode(), + ':{}'.format(self.console).encode(), + ) + ]) self._telnet_servers.append((yield from asyncio.start_server(server.run, self._manager.port_manager.console_host, self.console))) @asyncio.coroutine diff --git a/gns3server/utils/asyncio/raw_command_server.py b/gns3server/utils/asyncio/raw_command_server.py index 29f68a3c..df6d74d0 100644 --- a/gns3server/utils/asyncio/raw_command_server.py +++ b/gns3server/utils/asyncio/raw_command_server.py @@ -24,21 +24,27 @@ log = logging.getLogger(__name__) READ_SIZE = 4096 + class AsyncioRawCommandServer: """ Expose a process on the network his stdoud and stdin will be forward on network """ - def __init__(self, command): + def __init__(self, command, replaces=[]): + """ + :param command: Command to run + :param replaces: List of tuple to replace in the output ex: [(b":8080", b":6000")] + """ self._command = command + self._replaces = replaces @asyncio.coroutine def run(self, network_reader, network_writer): process = yield from asyncio.subprocess.create_subprocess_exec(*self._command, - stdout=asyncio.subprocess.PIPE, - stderr=asyncio.subprocess.STDOUT, - stdin=asyncio.subprocess.PIPE) + stdout=asyncio.subprocess.PIPE, + stderr=asyncio.subprocess.STDOUT, + stdin=asyncio.subprocess.PIPE) try: yield from self._process(network_reader, network_writer, process.stdout, process.stdin) except ConnectionResetError: @@ -73,6 +79,8 @@ class AsyncioRawCommandServer: reader_read = asyncio.async(process_reader.read(READ_SIZE)) + for replace in self._replaces: + data = data.replace(replace[0], replace[1]) network_writer.write(data) yield from network_writer.drain()