From d762c43314358c4dd2f21530fd5195da800cc9b7 Mon Sep 17 00:00:00 2001 From: grossmj Date: Sat, 28 Feb 2015 15:00:00 -0700 Subject: [PATCH] Include the images directory when converting an old project. --- gns3server/modules/base_manager.py | 30 ++++++++++++++++++------- gns3server/modules/dynamips/__init__.py | 2 +- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/gns3server/modules/base_manager.py b/gns3server/modules/base_manager.py index 7aec4a13..03c0cab5 100644 --- a/gns3server/modules/base_manager.py +++ b/gns3server/modules/base_manager.py @@ -166,23 +166,37 @@ class BaseManager: # move old project VM files to a new location log.info("Converting old project...") project_name = os.path.basename(project.path) - project_files_dir = os.path.join(project.path, "{}-files".format(project_name)) + legacy_project_files_path = os.path.join(project.path, "{}-files".format(project_name)) legacy_vm_dir = self.get_legacy_vm_workdir(legacy_id, name) - vm_working_dir = os.path.join(project_files_dir, legacy_vm_dir) - new_vm_working_dir = os.path.join(project.path, "project-files", self.module_name.lower(), vm_id) + legacy_vm_working_path = os.path.join(legacy_project_files_path, legacy_vm_dir) + new_project_files_path = os.path.join(project.path, "project-files") + new_vm_working_path = os.path.join(new_project_files_path, self.module_name.lower(), vm_id) try: - log.info('Moving "{}" to "{}"'.format(vm_working_dir, new_vm_working_dir)) - yield from wait_run_in_executor(shutil.move, vm_working_dir, new_vm_working_dir) + log.info('Moving "{}" to "{}"'.format(legacy_vm_working_path, new_vm_working_path)) + yield from wait_run_in_executor(shutil.move, legacy_vm_working_path, new_vm_working_path) except OSError as e: - raise aiohttp.web.HTTPInternalServerError(text="Could not move VM working directory: {} to {} {}".format(vm_working_dir, new_vm_working_dir, e)) + raise aiohttp.web.HTTPInternalServerError(text="Could not move VM working directory: {} to {} {}".format(legacy_vm_working_path, + new_vm_working_path, + e)) + + old_images_dir = os.path.join(legacy_project_files_path, "images") + new_images_dir = os.path.join(new_project_files_path, "images") + if os.path.isdir(old_images_dir): + try: + log.info('Moving "{}" to "{}"'.format(old_images_dir, new_images_dir)) + yield from wait_run_in_executor(shutil.move, old_images_dir, new_images_dir) + except OSError as e: + raise aiohttp.web.HTTPInternalServerError(text="Could not move images directory: {} to {} {}".format(old_images_dir, + new_images_dir, + e)) try: - os.rmdir(os.path.dirname(vm_working_dir)) + os.rmdir(os.path.dirname(legacy_vm_working_path)) except OSError: pass try: - os.rmdir(project_files_dir) + os.rmdir(legacy_project_files_path) except OSError: pass diff --git a/gns3server/modules/dynamips/__init__.py b/gns3server/modules/dynamips/__init__.py index 0b19c0be..6f2f60b1 100644 --- a/gns3server/modules/dynamips/__init__.py +++ b/gns3server/modules/dynamips/__init__.py @@ -180,7 +180,7 @@ class Dynamips(BaseManager): :param project: Project instance """ - for vm in self._vms: + for vm in self._vms.values(): if vm.project.id == project.id: yield from vm.hypervisor.set_working_dir(project.module_working_directory(self.module_name.lower()))