mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 17:28:08 +00:00
Prevent error when quick close of gns3 server after docker usage
Fix #382
This commit is contained in:
parent
8cf55166cb
commit
061b459abe
@ -44,6 +44,9 @@ class Docker(BaseManager):
|
|||||||
# Allow locking during ubridge operations
|
# Allow locking during ubridge operations
|
||||||
self.ubridge_lock = asyncio.Lock()
|
self.ubridge_lock = asyncio.Lock()
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
self._connector.close()
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def query(self, method, path, data={}, params={}):
|
def query(self, method, path, data={}, params={}):
|
||||||
"""
|
"""
|
||||||
|
@ -248,20 +248,25 @@ class DockerVM(BaseVM):
|
|||||||
def stop(self):
|
def stop(self):
|
||||||
"""Stops this Docker container."""
|
"""Stops this Docker container."""
|
||||||
|
|
||||||
if self._ubridge_hypervisor and self._ubridge_hypervisor.is_running():
|
try:
|
||||||
yield from self._ubridge_hypervisor.stop()
|
if self._ubridge_hypervisor and self._ubridge_hypervisor.is_running():
|
||||||
|
yield from self._ubridge_hypervisor.stop()
|
||||||
|
|
||||||
state = yield from self._get_container_state()
|
state = yield from self._get_container_state()
|
||||||
if state == "paused":
|
if state == "paused":
|
||||||
yield from self.unpause()
|
yield from self.unpause()
|
||||||
|
|
||||||
if self._telnet_server:
|
if self._telnet_server:
|
||||||
self._telnet_server.close()
|
self._telnet_server.close()
|
||||||
self._telnet_server = None
|
self._telnet_server = None
|
||||||
# t=5 number of seconds to wait before killing the container
|
# t=5 number of seconds to wait before killing the container
|
||||||
yield from self.manager.query("POST", "containers/{}/stop".format(self._cid), params={"t": 5})
|
yield from self.manager.query("POST", "containers/{}/stop".format(self._cid), params={"t": 5})
|
||||||
log.info("Docker container '{name}' [{image}] stopped".format(
|
log.info("Docker container '{name}' [{image}] stopped".format(
|
||||||
name=self._name, image=self._image))
|
name=self._name, image=self._image))
|
||||||
|
# Ignore runtime error because when closing the server
|
||||||
|
except RuntimeError as e:
|
||||||
|
log.debug("Docker runtime error when closing: {}".format(str(e)))
|
||||||
|
return
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def pause(self):
|
def pause(self):
|
||||||
@ -282,24 +287,30 @@ class DockerVM(BaseVM):
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def remove(self):
|
def remove(self):
|
||||||
"""Removes this Docker container."""
|
"""Removes this Docker container."""
|
||||||
state = yield from self._get_container_state()
|
|
||||||
if state == "paused":
|
|
||||||
yield from self.unpause()
|
|
||||||
if state == "running":
|
|
||||||
yield from self.stop()
|
|
||||||
yield from self.manager.query("DELETE", "containers/{}".format(self._cid), params={"force": 1})
|
|
||||||
log.info("Docker container '{name}' [{image}] removed".format(
|
|
||||||
name=self._name, image=self._image))
|
|
||||||
|
|
||||||
if self._console:
|
try:
|
||||||
self._manager.port_manager.release_tcp_port(self._console, self._project)
|
state = yield from self._get_container_state()
|
||||||
self._console = None
|
if state == "paused":
|
||||||
|
yield from self.unpause()
|
||||||
|
if state == "running":
|
||||||
|
yield from self.stop()
|
||||||
|
yield from self.manager.query("DELETE", "containers/{}".format(self._cid), params={"force": 1})
|
||||||
|
log.info("Docker container '{name}' [{image}] removed".format(
|
||||||
|
name=self._name, image=self._image))
|
||||||
|
|
||||||
for adapter in self._ethernet_adapters:
|
if self._console:
|
||||||
if adapter is not None:
|
self._manager.port_manager.release_tcp_port(self._console, self._project)
|
||||||
for nio in adapter.ports.values():
|
self._console = None
|
||||||
if nio and isinstance(nio, NIOUDP):
|
|
||||||
self.manager.port_manager.release_udp_port(nio.lport, self._project)
|
for adapter in self._ethernet_adapters:
|
||||||
|
if adapter is not None:
|
||||||
|
for nio in adapter.ports.values():
|
||||||
|
if nio and isinstance(nio, NIOUDP):
|
||||||
|
self.manager.port_manager.release_udp_port(nio.lport, self._project)
|
||||||
|
# Ignore runtime error because when closing the server
|
||||||
|
except RuntimeError as e:
|
||||||
|
log.debug("Docker runtime error when closing: {}".format(str(e)))
|
||||||
|
return
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def close(self):
|
def close(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user