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.
This commit is contained in:
grossmj 2015-03-01 19:20:33 -07:00
parent 3ef529fb0e
commit c48ca212bd
3 changed files with 23 additions and 3 deletions

View File

@ -121,6 +121,8 @@ class ProjectHandler:
pm = ProjectManager.instance() pm = ProjectManager.instance()
project = pm.get_project(request.match_info["project_id"]) project = pm.get_project(request.match_info["project_id"])
for module in MODULES:
yield from module.instance().project_closing(project)
yield from project.close() yield from project.close()
for module in MODULES: for module in MODULES:
yield from module.instance().project_closed(project) yield from module.instance().project_closed(project)

View File

@ -234,6 +234,16 @@ class BaseManager:
vm.close() vm.close()
return vm 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 @asyncio.coroutine
def project_closed(self, project): def project_closed(self, project):
""" """

View File

@ -136,9 +136,9 @@ class Dynamips(BaseManager):
continue continue
@asyncio.coroutine @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 :param project: Project instance
""" """
@ -157,7 +157,15 @@ class Dynamips(BaseManager):
except Exception as e: except Exception as e:
log.error("Could not delete device {}".format(e), exc_info=1) 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()) 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, "*.ghost"))
files += glob.glob(os.path.join(project_dir, "*_lock")) files += glob.glob(os.path.join(project_dir, "*_lock"))