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

Save Dynamips VM configs when closing a project.

This commit is contained in:
Jeremy 2015-02-16 18:21:10 -07:00
parent 516b882122
commit e6fd471dd5
2 changed files with 26 additions and 19 deletions

View File

@ -160,6 +160,8 @@ class Dynamips(BaseManager):
files += glob.glob(os.path.join(project_dir, "ilt_*"))
files += glob.glob(os.path.join(project_dir, "c[0-9][0-9][0-9][0-9]_*_rommon_vars"))
files += glob.glob(os.path.join(project_dir, "c[0-9][0-9][0-9][0-9]_*_ssa"))
files += glob.glob(os.path.join(project_dir, "dynamips_log*"))
files += glob.glob(os.path.join(project_dir, "*_log.txt"))
for file in files:
try:
log.debug("Deleting file {}".format(file))
@ -415,24 +417,27 @@ class Dynamips(BaseManager):
# create a new ghost IOS instance
ghost_id = str(uuid4())
ghost = Router("ghost-" + ghost_file, ghost_id, vm.project, vm.manager, platform=vm.platform, hypervisor=vm.hypervisor, ghost_flag=True)
yield from ghost.create()
yield from ghost.set_image(vm.image)
# for 7200s, the NPE must be set when using an NPE-G2.
if vm.platform == "c7200":
yield from ghost.set_npe(vm.npe)
yield from ghost.set_ghost_status(1)
yield from ghost.set_ghost_file(ghost_file)
yield from ghost.set_ram(vm.ram)
try:
yield from ghost.start()
yield from ghost.stop()
self._ghost_files.add(ghost_file_path)
except DynamipsError:
raise
finally:
yield from ghost.clean_delete()
yield from ghost.create()
yield from ghost.set_image(vm.image)
# for 7200s, the NPE must be set when using an NPE-G2.
if vm.platform == "c7200":
yield from ghost.set_npe(vm.npe)
yield from ghost.set_ghost_status(1)
yield from ghost.set_ghost_file(ghost_file)
yield from ghost.set_ram(vm.ram)
try:
yield from ghost.start()
yield from ghost.stop()
self._ghost_files.add(ghost_file_path)
except DynamipsError:
raise
finally:
yield from ghost.clean_delete()
except DynamipsError as e:
log.warn("Could not create ghost instance: {}".format(e))
if vm.ghost_file != ghost_file:
if vm.ghost_file != ghost_file and os.path.isfile(ghost_file):
# set the ghost file to the router
yield from vm.set_ghost_status(2)
yield from vm.set_ghost_file(ghost_file)
@ -487,8 +492,9 @@ class Dynamips(BaseManager):
:param private_config_content: content of the private-config
"""
default_startup_config_path = os.path.join(vm.project.vm_working_directory(vm), "configs", "i{}_startup-config.cfg".format(vm.dynamips_id))
default_private_config_path = os.path.join(vm.project.vm_working_directory(vm), "configs", "i{}_private-config.cfg".format(vm.dynamips_id))
module_workdir = vm.project.module_working_directory(self.module_name.lower())
default_startup_config_path = os.path.join(module_workdir, "configs", "i{}_startup-config.cfg".format(vm.dynamips_id))
default_private_config_path = os.path.join(module_workdir, "configs", "i{}_private-config.cfg".format(vm.dynamips_id))
if startup_config_content:
startup_config_path = self._create_config(vm, startup_config_content, default_startup_config_path)

View File

@ -315,6 +315,7 @@ class Router(BaseVM):
if self._hypervisor and not self._hypervisor.devices:
try:
yield from self.stop()
yield from self.save_configs()
yield from self._hypervisor.send('vm delete "{}"'.format(self._name))
except DynamipsError:
pass
@ -1563,7 +1564,7 @@ class Router(BaseVM):
continue
@asyncio.coroutine
def clean_delete(self, stop_hypervisor=False):
def clean_delete(self):
"""
Deletes this router & associated files (nvram, disks etc.)
"""