diff --git a/gns3server/handlers/api/server_handler.py b/gns3server/handlers/api/server_handler.py index 65e8892f..105129f2 100644 --- a/gns3server/handlers/api/server_handler.py +++ b/gns3server/handlers/api/server_handler.py @@ -17,8 +17,14 @@ from ...web.route import Route from ...config import Config +from ...modules.project_manager import ProjectManager from aiohttp.web import HTTPForbidden + import asyncio +import logging + +log = logging.getLogger(__name__) + class ServerHandler: @@ -36,6 +42,24 @@ class ServerHandler: if config.get_section_config("Server").getboolean("local", False) is False: 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 server = Server.instance() asyncio.async(server.shutdown_server()) diff --git a/gns3server/modules/iou/iou_vm.py b/gns3server/modules/iou/iou_vm.py index 7325a8ea..36e2e7c0 100644 --- a/gns3server/modules/iou/iou_vm.py +++ b/gns3server/modules/iou/iou_vm.py @@ -401,7 +401,7 @@ class IOUVM(BaseVM): if iourc_path and not os.path.isfile(iourc_path): 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: yield from self._check_iou_licence() diff --git a/gns3server/modules/project_manager.py b/gns3server/modules/project_manager.py index 454b3114..4ea21612 100644 --- a/gns3server/modules/project_manager.py +++ b/gns3server/modules/project_manager.py @@ -42,6 +42,16 @@ class ProjectManager: cls._instance = cls() return cls._instance + @property + def projects(self): + """ + Returns all projects. + + :returns: Project instances + """ + + return self._projects.values() + def get_project(self, project_id): """ Returns a Project instance. diff --git a/gns3server/server.py b/gns3server/server.py index d1f51471..dca8ff29 100644 --- a/gns3server/server.py +++ b/gns3server/server.py @@ -190,8 +190,8 @@ class Server: # 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. def wakeup(): - loop.call_later(0.1, wakeup) - loop.call_later(0.1, wakeup) + loop.call_later(0.5, wakeup) + loop.call_later(0.5, wakeup) asyncio.set_event_loop(loop) ssl_context = None