From c48ca212bd81328ca8ac2cbf4b4c62332da71ae3 Mon Sep 17 00:00:00 2001 From: grossmj Date: Sun, 1 Mar 2015 19:20:33 -0700 Subject: [PATCH] Stop Dynamips hypervisors used by devices before the project is closed. This is to avoid locked files by hypervisors preventing temporary project working directories to be deleted. --- gns3server/handlers/api/project_handler.py | 2 ++ gns3server/modules/base_manager.py | 10 ++++++++++ gns3server/modules/dynamips/__init__.py | 14 +++++++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/gns3server/handlers/api/project_handler.py b/gns3server/handlers/api/project_handler.py index 7477de25..3f9d9f4a 100644 --- a/gns3server/handlers/api/project_handler.py +++ b/gns3server/handlers/api/project_handler.py @@ -121,6 +121,8 @@ class ProjectHandler: pm = ProjectManager.instance() project = pm.get_project(request.match_info["project_id"]) + for module in MODULES: + yield from module.instance().project_closing(project) yield from project.close() for module in MODULES: yield from module.instance().project_closed(project) diff --git a/gns3server/modules/base_manager.py b/gns3server/modules/base_manager.py index ebdf7f0c..e318e0fc 100644 --- a/gns3server/modules/base_manager.py +++ b/gns3server/modules/base_manager.py @@ -234,6 +234,16 @@ class BaseManager: vm.close() return vm + @asyncio.coroutine + def project_closing(self, project): + """ + Called when a project is about to be closed. + + :param project: Project instance + """ + + pass + @asyncio.coroutine def project_closed(self, project): """ diff --git a/gns3server/modules/dynamips/__init__.py b/gns3server/modules/dynamips/__init__.py index c02e7494..a0c54612 100644 --- a/gns3server/modules/dynamips/__init__.py +++ b/gns3server/modules/dynamips/__init__.py @@ -136,9 +136,9 @@ class Dynamips(BaseManager): continue @asyncio.coroutine - def project_closed(self, project): + def project_closing(self, project): """ - Called when a project is closed. + Called when a project is about to be closed. :param project: Project instance """ @@ -157,7 +157,15 @@ class Dynamips(BaseManager): except Exception as e: log.error("Could not delete device {}".format(e), exc_info=1) - # delete useless files + @asyncio.coroutine + def project_closed(self, project): + """ + Called when a project is closed. + + :param project: Project instance + """ + + # delete useless Dynamips files project_dir = project.module_working_directory(self.module_name.lower()) files = glob.glob(os.path.join(project_dir, "*.ghost")) files += glob.glob(os.path.join(project_dir, "*_lock"))