Update hypervisors working dir when the project is moved.

pull/100/head
Jeremy 9 years ago
parent b55719186e
commit 0e8b8fa66f

@ -81,7 +81,11 @@ class ProjectHandler:
pm = ProjectManager.instance()
project = pm.get_project(request.match_info["project_id"])
project.temporary = request.json.get("temporary", project.temporary)
project.path = request.json.get("path", project.path)
project_path = request.json.get("path", project.path)
if project_path != project.path:
project.path = project_path
for module in MODULES:
yield from module.instance().project_moved(project)
response.json(project)
@classmethod
@ -119,7 +123,7 @@ class ProjectHandler:
project = pm.get_project(request.match_info["project_id"])
yield from project.close()
for module in MODULES:
yield from module.instance().project_closed(project.path)
yield from module.instance().project_closed(project)
pm.remove_project(project.id)
response.set_status(204)

@ -233,11 +233,21 @@ class BaseManager:
return vm
@asyncio.coroutine
def project_closed(self, project_dir):
def project_closed(self, project):
"""
Called when a project is closed.
:param project_dir: project directory
:param project: Project instance
"""
pass
@asyncio.coroutine
def project_moved(self, project):
"""
Called when a project is moved
:param project: project instance
"""
pass

@ -133,17 +133,18 @@ class Dynamips(BaseManager):
continue
@asyncio.coroutine
def project_closed(self, project_dir):
def project_closed(self, project):
"""
Called when a project is closed.
:param project_dir: project directory
:param project: Project instance
"""
# delete the Dynamips devices
# delete the Dynamips devices corresponding to the project
tasks = []
for device in self._devices.values():
tasks.append(asyncio.async(device.delete()))
if device.project.id == project.id:
tasks.append(asyncio.async(device.delete()))
if tasks:
done, _ = yield from asyncio.wait(tasks)
@ -154,7 +155,7 @@ class Dynamips(BaseManager):
log.error("Could not delete device {}".format(e), exc_info=1)
# delete useless files
project_dir = os.path.join(project_dir, 'project-files', 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, "*_lock"))
files += glob.glob(os.path.join(project_dir, "ilt_*"))
@ -170,6 +171,21 @@ class Dynamips(BaseManager):
log.warn("Could not delete file {}: {}".format(file, e))
continue
@asyncio.coroutine
def project_moved(self, project):
"""
Called when a project is moved.
:param project: Project instance
"""
for vm in project.vms:
yield from vm.hypervisor.set_working_dir(project.module_working_directory(self.module_name.lower()))
for device in self._devices.values():
if device.project.id == project.id:
yield from device.hypervisor.set_working_dir(project.module_working_directory(self.module_name.lower()))
@property
def dynamips_path(self):
"""

@ -146,7 +146,7 @@ class DynamipsHypervisor:
"""
# encase working_dir in quotes to protect spaces in the path
yield from self.send("hypervisor working_dir {}".format('"' + working_dir + '"'))
yield from self.send('hypervisor working_dir "{}"'.format(working_dir))
self._working_dir = working_dir
log.debug("Working directory set to {}".format(self._working_dir))

Loading…
Cancel
Save