mirror of
https://github.com/GNS3/gns3-server.git
synced 2025-01-18 07:23:47 +02:00
Alternative local server shutdown (mostly intended for Windows).
This commit is contained in:
parent
4ccca5dc99
commit
cf92bfe81e
@ -17,8 +17,14 @@
|
|||||||
|
|
||||||
from ...web.route import Route
|
from ...web.route import Route
|
||||||
from ...config import Config
|
from ...config import Config
|
||||||
|
from ...modules.project_manager import ProjectManager
|
||||||
from aiohttp.web import HTTPForbidden
|
from aiohttp.web import HTTPForbidden
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import logging
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ServerHandler:
|
class ServerHandler:
|
||||||
|
|
||||||
@ -36,6 +42,24 @@ class ServerHandler:
|
|||||||
if config.get_section_config("Server").getboolean("local", False) is False:
|
if config.get_section_config("Server").getboolean("local", False) is False:
|
||||||
raise HTTPForbidden(text="You can only stop a local server")
|
raise HTTPForbidden(text="You can only stop a local server")
|
||||||
|
|
||||||
|
# close all the projects first
|
||||||
|
pm = ProjectManager.instance()
|
||||||
|
projects = pm.projects
|
||||||
|
|
||||||
|
tasks = []
|
||||||
|
for project in projects:
|
||||||
|
tasks.append(asyncio.async(project.close()))
|
||||||
|
|
||||||
|
if tasks:
|
||||||
|
done, _ = yield from asyncio.wait(tasks)
|
||||||
|
for future in done:
|
||||||
|
try:
|
||||||
|
future.result()
|
||||||
|
except Exception as e:
|
||||||
|
log.error("Could not close project {}".format(e), exc_info=1)
|
||||||
|
continue
|
||||||
|
|
||||||
|
# then shutdown the server itself
|
||||||
from gns3server.server import Server
|
from gns3server.server import Server
|
||||||
server = Server.instance()
|
server = Server.instance()
|
||||||
asyncio.async(server.shutdown_server())
|
asyncio.async(server.shutdown_server())
|
||||||
|
@ -401,7 +401,7 @@ class IOUVM(BaseVM):
|
|||||||
if iourc_path and not os.path.isfile(iourc_path):
|
if iourc_path and not os.path.isfile(iourc_path):
|
||||||
raise IOUError("A valid iourc file is necessary to start IOU")
|
raise IOUError("A valid iourc file is necessary to start IOU")
|
||||||
|
|
||||||
license_check = self._manager.config.get_section_config("IOU").getboolean("license_check", True)
|
license_check = self._manager.config.get_section_config("IOU").getboolean("license_check", False)
|
||||||
if license_check:
|
if license_check:
|
||||||
yield from self._check_iou_licence()
|
yield from self._check_iou_licence()
|
||||||
|
|
||||||
|
@ -42,6 +42,16 @@ class ProjectManager:
|
|||||||
cls._instance = cls()
|
cls._instance = cls()
|
||||||
return cls._instance
|
return cls._instance
|
||||||
|
|
||||||
|
@property
|
||||||
|
def projects(self):
|
||||||
|
"""
|
||||||
|
Returns all projects.
|
||||||
|
|
||||||
|
:returns: Project instances
|
||||||
|
"""
|
||||||
|
|
||||||
|
return self._projects.values()
|
||||||
|
|
||||||
def get_project(self, project_id):
|
def get_project(self, project_id):
|
||||||
"""
|
"""
|
||||||
Returns a Project instance.
|
Returns a Project instance.
|
||||||
|
@ -190,8 +190,8 @@ class Server:
|
|||||||
# because asyncio.add_signal_handler() is not supported yet on that platform
|
# because asyncio.add_signal_handler() is not supported yet on that platform
|
||||||
# otherwise the loop runs outside of signal module's ability to trap signals.
|
# otherwise the loop runs outside of signal module's ability to trap signals.
|
||||||
def wakeup():
|
def wakeup():
|
||||||
loop.call_later(0.1, wakeup)
|
loop.call_later(0.5, wakeup)
|
||||||
loop.call_later(0.1, wakeup)
|
loop.call_later(0.5, wakeup)
|
||||||
asyncio.set_event_loop(loop)
|
asyncio.set_event_loop(loop)
|
||||||
|
|
||||||
ssl_context = None
|
ssl_context = None
|
||||||
|
Loading…
Reference in New Issue
Block a user