1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-25 00:08:11 +00:00

Save IOS router configs when saving the project (done right this time).

This commit is contained in:
Jeremy 2015-03-18 15:34:31 -06:00
parent f6b122cdfa
commit 8415117d2d
4 changed files with 24 additions and 37 deletions

View File

@ -15,10 +15,8 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import os import os
import base64 import base64
import asyncio
from ...web.route import Route from ...web.route import Route
from ...schemas.dynamips_vm import VM_CREATE_SCHEMA from ...schemas.dynamips_vm import VM_CREATE_SCHEMA
@ -341,7 +339,7 @@ class DynamipsVMHandler:
}, },
output=VM_CONFIGS_SCHEMA, output=VM_CONFIGS_SCHEMA,
description="Retrieve the startup and private configs content") description="Retrieve the startup and private configs content")
def show_initial_config(request, response): def get_configs(request, response):
dynamips_manager = Dynamips.instance() dynamips_manager = Dynamips.instance()
vm = dynamips_manager.get_vm(request.match_info["vm_id"], vm = dynamips_manager.get_vm(request.match_info["vm_id"],
@ -355,6 +353,23 @@ class DynamipsVMHandler:
response.json({"startup_config_content": startup_config_content, response.json({"startup_config_content": startup_config_content,
"private_config_content": private_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( @Route.get(
r"/projects/{project_id}/dynamips/vms/{vm_id}/idlepc_proposals", r"/projects/{project_id}/dynamips/vms/{vm_id}/idlepc_proposals",
status_codes={ status_codes={

View File

@ -282,16 +282,6 @@ class BaseManager:
pass pass
@asyncio.coroutine
def project_committed(self, project):
"""
Called when a project is committed.
:param project: Project instance
"""
pass
@asyncio.coroutine @asyncio.coroutine
def delete_vm(self, vm_id): def delete_vm(self, vm_id):
""" """

View File

@ -115,7 +115,6 @@ class Dynamips(BaseManager):
self._devices = {} self._devices = {}
self._ghost_files = set() self._ghost_files = set()
self._dynamips_path = None self._dynamips_path = None
self._project_lock = asyncio.Lock()
@asyncio.coroutine @asyncio.coroutine
def unload(self): def unload(self):
@ -192,7 +191,6 @@ class Dynamips(BaseManager):
:param project: Project instance :param project: Project instance
""" """
with (yield from self._project_lock):
for vm in self._vms.values(): for vm in self._vms.values():
if vm.project.id == project.id: if vm.project.id == project.id:
yield from vm.hypervisor.set_working_dir(project.module_working_directory(self.module_name.lower())) yield from vm.hypervisor.set_working_dir(project.module_working_directory(self.module_name.lower()))
@ -201,20 +199,6 @@ class Dynamips(BaseManager):
if device.project.id == project.id: if device.project.id == project.id:
yield from device.hypervisor.set_working_dir(project.module_working_directory(self.module_name.lower())) 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()
@property @property
def dynamips_path(self): def dynamips_path(self):
""" """

View File

@ -324,8 +324,6 @@ class Project:
vm = self._vms_to_destroy.pop() vm = self._vms_to_destroy.pop()
yield from vm.delete() yield from vm.delete()
self.remove_vm(vm) self.remove_vm(vm)
for module in self.modules():
yield from module.instance().project_committed(self)
@asyncio.coroutine @asyncio.coroutine
def delete(self): def delete(self):