1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-26 16:58:28 +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, "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]_*_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, "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: for file in files:
try: try:
log.debug("Deleting file {}".format(file)) log.debug("Deleting file {}".format(file))
@ -415,6 +417,7 @@ class Dynamips(BaseManager):
# create a new ghost IOS instance # create a new ghost IOS instance
ghost_id = str(uuid4()) ghost_id = str(uuid4())
ghost = Router("ghost-" + ghost_file, ghost_id, vm.project, vm.manager, platform=vm.platform, hypervisor=vm.hypervisor, ghost_flag=True) ghost = Router("ghost-" + ghost_file, ghost_id, vm.project, vm.manager, platform=vm.platform, hypervisor=vm.hypervisor, ghost_flag=True)
try:
yield from ghost.create() yield from ghost.create()
yield from ghost.set_image(vm.image) yield from ghost.set_image(vm.image)
# for 7200s, the NPE must be set when using an NPE-G2. # for 7200s, the NPE must be set when using an NPE-G2.
@ -431,8 +434,10 @@ class Dynamips(BaseManager):
raise raise
finally: finally:
yield from ghost.clean_delete() 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 # set the ghost file to the router
yield from vm.set_ghost_status(2) yield from vm.set_ghost_status(2)
yield from vm.set_ghost_file(ghost_file) yield from vm.set_ghost_file(ghost_file)
@ -487,8 +492,9 @@ class Dynamips(BaseManager):
:param private_config_content: content of the private-config :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)) module_workdir = vm.project.module_working_directory(self.module_name.lower())
default_private_config_path = os.path.join(vm.project.vm_working_directory(vm), "configs", "i{}_private-config.cfg".format(vm.dynamips_id)) 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: if startup_config_content:
startup_config_path = self._create_config(vm, startup_config_content, default_startup_config_path) 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: if self._hypervisor and not self._hypervisor.devices:
try: try:
yield from self.stop() yield from self.stop()
yield from self.save_configs()
yield from self._hypervisor.send('vm delete "{}"'.format(self._name)) yield from self._hypervisor.send('vm delete "{}"'.format(self._name))
except DynamipsError: except DynamipsError:
pass pass
@ -1563,7 +1564,7 @@ class Router(BaseVM):
continue continue
@asyncio.coroutine @asyncio.coroutine
def clean_delete(self, stop_hypervisor=False): def clean_delete(self):
""" """
Deletes this router & associated files (nvram, disks etc.) Deletes this router & associated files (nvram, disks etc.)
""" """