1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-26 00:38:10 +00:00

Ensure that the connection to docker is closed when leaving server

Fix https://github.com/GNS3/gns3-gui/issues/1227
This commit is contained in:
Julien Duponchelle 2016-05-10 12:14:48 +02:00
parent 28f7c2a1cd
commit 9e2043bfa8
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 7 additions and 4 deletions

View File

@ -61,7 +61,9 @@ class Docker(BaseManager):
raise DockerError("Docker API version is {}. GNS3 requires a minimum API version of {}".format(version["ApiVersion"], DOCKER_MINIMUM_API_VERSION)) raise DockerError("Docker API version is {}. GNS3 requires a minimum API version of {}".format(version["ApiVersion"], DOCKER_MINIMUM_API_VERSION))
return self._connector return self._connector
def __del__(self): @asyncio.coroutine
def unload(self):
yield from super().unload()
if self._connected: if self._connected:
self._connector.close() self._connector.close()

View File

@ -77,6 +77,7 @@ class DockerVM(BaseVM):
self._console_resolution = console_resolution self._console_resolution = console_resolution
self._console_http_path = console_http_path self._console_http_path = console_http_path
self._console_http_port = console_http_port self._console_http_port = console_http_port
self._console_websocket = None
if adapters is None: if adapters is None:
self.adapters = 1 self.adapters = 1
@ -433,12 +434,12 @@ class DockerVM(BaseVM):
telnet = AsyncioTelnetServer(reader=output_stream, writer=input_stream, echo=True) 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._telnet_servers.append((yield from asyncio.start_server(telnet.run, self._manager.port_manager.console_host, self.console)))
ws = yield from self.manager.websocket_query("containers/{}/attach/ws?stream=1&stdin=1&stdout=1&stderr=1".format(self._cid)) 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 = ws 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") 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(ws, output_stream)) asyncio.async(self._read_console_output(self._console_websocket, output_stream))
@asyncio.coroutine @asyncio.coroutine
def _read_console_output(self, ws, out): def _read_console_output(self, ws, out):