1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

Alternative local server shutdown (mostly intended for Windows).

This commit is contained in:
Jeremy 2015-03-13 18:57:27 -06:00
parent 4ccca5dc99
commit cf92bfe81e
4 changed files with 37 additions and 3 deletions

View File

@ -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())

View File

@ -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()

View File

@ -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.

View File

@ -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