From 8415117d2dd219f3523e77a4fdb639cbc53f8093 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Wed, 18 Mar 2015 15:34:31 -0600 Subject: [PATCH] Save IOS router configs when saving the project (done right this time). --- .../handlers/api/dynamips_vm_handler.py | 21 ++++++++++++-- gns3server/modules/base_manager.py | 10 ------- gns3server/modules/dynamips/__init__.py | 28 ++++--------------- gns3server/modules/project.py | 2 -- 4 files changed, 24 insertions(+), 37 deletions(-) diff --git a/gns3server/handlers/api/dynamips_vm_handler.py b/gns3server/handlers/api/dynamips_vm_handler.py index dd5d5720..1aea6a7b 100644 --- a/gns3server/handlers/api/dynamips_vm_handler.py +++ b/gns3server/handlers/api/dynamips_vm_handler.py @@ -15,10 +15,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . - import os import base64 -import asyncio from ...web.route import Route from ...schemas.dynamips_vm import VM_CREATE_SCHEMA @@ -341,7 +339,7 @@ class DynamipsVMHandler: }, output=VM_CONFIGS_SCHEMA, description="Retrieve the startup and private configs content") - def show_initial_config(request, response): + def get_configs(request, response): dynamips_manager = Dynamips.instance() vm = dynamips_manager.get_vm(request.match_info["vm_id"], @@ -355,6 +353,23 @@ class DynamipsVMHandler: response.json({"startup_config_content": startup_config_content, "private_config_content": private_config_content}) + @Route.post( + r"/projects/{project_id}/dynamips/vms/{vm_id}/configs/save", + status_codes={ + 200: "Configs saved", + 400: "Invalid request", + 404: "Instance doesn't exist" + }, + description="Save the startup and private configs content") + def save_configs(request, response): + + dynamips_manager = Dynamips.instance() + vm = dynamips_manager.get_vm(request.match_info["vm_id"], + project_id=request.match_info["project_id"]) + + yield from vm.save_configs() + response.set_status(200) + @Route.get( r"/projects/{project_id}/dynamips/vms/{vm_id}/idlepc_proposals", status_codes={ diff --git a/gns3server/modules/base_manager.py b/gns3server/modules/base_manager.py index c41463a7..23a4e34d 100644 --- a/gns3server/modules/base_manager.py +++ b/gns3server/modules/base_manager.py @@ -282,16 +282,6 @@ class BaseManager: pass - @asyncio.coroutine - def project_committed(self, project): - """ - Called when a project is committed. - - :param project: Project instance - """ - - pass - @asyncio.coroutine def delete_vm(self, vm_id): """ diff --git a/gns3server/modules/dynamips/__init__.py b/gns3server/modules/dynamips/__init__.py index b36169e1..6a5f4c70 100644 --- a/gns3server/modules/dynamips/__init__.py +++ b/gns3server/modules/dynamips/__init__.py @@ -115,7 +115,6 @@ class Dynamips(BaseManager): self._devices = {} self._ghost_files = set() self._dynamips_path = None - self._project_lock = asyncio.Lock() @asyncio.coroutine def unload(self): @@ -192,28 +191,13 @@ class Dynamips(BaseManager): :param project: Project instance """ - with (yield from self._project_lock): - 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())) + 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())) - 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())) - - @asyncio.coroutine - def project_committed(self, project): - """ - Called when a project has been committed. - - :param project: Project instance - """ - - # save the configs when the project is committed - with (yield from self._project_lock): - for vm in self._vms.values(): - if vm.project.id == project.id: - yield from vm.save_configs() + 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): diff --git a/gns3server/modules/project.py b/gns3server/modules/project.py index 4fc14b9b..8d1d449d 100644 --- a/gns3server/modules/project.py +++ b/gns3server/modules/project.py @@ -324,8 +324,6 @@ class Project: vm = self._vms_to_destroy.pop() yield from vm.delete() self.remove_vm(vm) - for module in self.modules(): - yield from module.instance().project_committed(self) @asyncio.coroutine def delete(self):