mirror of
https://github.com/GNS3/gns3-server.git
synced 2025-01-31 05:13:49 +02:00
Replace port in HTTP flow for docker
This commit is contained in:
parent
5fd385159c
commit
f3095d94c1
@ -393,7 +393,13 @@ class DockerVM(BaseVM):
|
|||||||
"""
|
"""
|
||||||
log.debug("Forward HTTP for %s to %d", self.name, self._console_http_port)
|
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)]
|
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)))
|
self._telnet_servers.append((yield from asyncio.start_server(server.run, self._manager.port_manager.console_host, self.console)))
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
@ -24,14 +24,20 @@ log = logging.getLogger(__name__)
|
|||||||
|
|
||||||
READ_SIZE = 4096
|
READ_SIZE = 4096
|
||||||
|
|
||||||
|
|
||||||
class AsyncioRawCommandServer:
|
class AsyncioRawCommandServer:
|
||||||
"""
|
"""
|
||||||
Expose a process on the network his stdoud and stdin will be forward
|
Expose a process on the network his stdoud and stdin will be forward
|
||||||
on network
|
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._command = command
|
||||||
|
self._replaces = replaces
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def run(self, network_reader, network_writer):
|
def run(self, network_reader, network_writer):
|
||||||
@ -73,6 +79,8 @@ class AsyncioRawCommandServer:
|
|||||||
|
|
||||||
reader_read = asyncio.async(process_reader.read(READ_SIZE))
|
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)
|
network_writer.write(data)
|
||||||
yield from network_writer.drain()
|
yield from network_writer.drain()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user