mirror of
https://github.com/GNS3/gns3-server
synced 2025-01-12 09:00:57 +00:00
Automatically extract IOS configs when a project is closed.
This commit is contained in:
parent
f44fbd1f16
commit
f6561bf684
@ -154,12 +154,16 @@ class Dynamips(IModule):
|
||||
if not sys.platform.startswith("win32"):
|
||||
self._callback.stop()
|
||||
|
||||
# automatically save configs for all router instances
|
||||
for router_id in self._routers:
|
||||
router = self._routers[router_id]
|
||||
router.save_configs()
|
||||
|
||||
# stop all Dynamips hypervisors
|
||||
if self._hypervisor_manager:
|
||||
self._hypervisor_manager.stop_all_hypervisors()
|
||||
|
||||
self.delete_dynamips_files()
|
||||
|
||||
IModule.stop(self, signum) # this will stop the I/O loop
|
||||
|
||||
def _check_hypervisors(self):
|
||||
@ -225,6 +229,11 @@ class Dynamips(IModule):
|
||||
:param request: JSON request (not used)
|
||||
"""
|
||||
|
||||
# automatically save configs for all router instances
|
||||
for router_id in self._routers:
|
||||
router = self._routers[router_id]
|
||||
router.save_configs()
|
||||
|
||||
# stop all Dynamips hypervisors
|
||||
if self._hypervisor_manager:
|
||||
self._hypervisor_manager.stop_all_hypervisors()
|
||||
|
@ -608,31 +608,7 @@ class VM(object):
|
||||
return
|
||||
|
||||
try:
|
||||
if router.startup_config or router.private_config:
|
||||
|
||||
startup_config_base64, private_config_base64 = router.extract_config()
|
||||
if startup_config_base64:
|
||||
try:
|
||||
config = base64.decodestring(startup_config_base64.encode("utf-8")).decode("utf-8")
|
||||
config = "!\n" + config.replace("\r", "")
|
||||
config_path = os.path.join(router.hypervisor.working_dir, router.startup_config)
|
||||
with open(config_path, "w") as f:
|
||||
log.info("saving startup-config to {}".format(router.startup_config))
|
||||
f.write(config)
|
||||
except OSError as e:
|
||||
raise DynamipsError("Could not save the startup configuration {}: {}".format(config_path, e))
|
||||
|
||||
if private_config_base64:
|
||||
try:
|
||||
config = base64.decodestring(private_config_base64.encode("utf-8")).decode("utf-8")
|
||||
config = "!\n" + config.replace("\r", "")
|
||||
config_path = os.path.join(router.hypervisor.working_dir, router.private_config)
|
||||
with open(config_path, "w") as f:
|
||||
log.info("saving private-config to {}".format(router.private_config))
|
||||
f.write(config)
|
||||
except OSError as e:
|
||||
raise DynamipsError("Could not save the private configuration {}: {}".format(config_path, e))
|
||||
|
||||
router.save_configs()
|
||||
except DynamipsError as e:
|
||||
log.warn("could not save config to {}: {}".format(router.startup_config, e))
|
||||
|
||||
|
@ -26,6 +26,7 @@ from ...attic import find_unused_port
|
||||
import time
|
||||
import sys
|
||||
import os
|
||||
import base64
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
@ -598,6 +599,35 @@ class Router(object):
|
||||
log.info("router {name} [id={id}]: new private-config pushed".format(name=self._name,
|
||||
id=self._id))
|
||||
|
||||
def save_configs(self):
|
||||
"""
|
||||
Saves the startup-config and private-config to files.
|
||||
"""
|
||||
|
||||
if self.startup_config or self.private_config:
|
||||
startup_config_base64, private_config_base64 = self.extract_config()
|
||||
if startup_config_base64:
|
||||
try:
|
||||
config = base64.decodebytes(startup_config_base64.encode("utf-8")).decode("utf-8")
|
||||
config = "!\n" + config.replace("\r", "")
|
||||
config_path = os.path.join(self.hypervisor.working_dir, self.startup_config)
|
||||
with open(config_path, "w") as f:
|
||||
log.info("saving startup-config to {}".format(self.startup_config))
|
||||
f.write(config)
|
||||
except OSError as e:
|
||||
raise DynamipsError("Could not save the startup configuration {}: {}".format(config_path, e))
|
||||
|
||||
if private_config_base64:
|
||||
try:
|
||||
config = base64.decodebytes(private_config_base64.encode("utf-8")).decode("utf-8")
|
||||
config = "!\n" + config.replace("\r", "")
|
||||
config_path = os.path.join(self.hypervisor.working_dir, self.private_config)
|
||||
with open(config_path, "w") as f:
|
||||
log.info("saving private-config to {}".format(self.private_config))
|
||||
f.write(config)
|
||||
except OSError as e:
|
||||
raise DynamipsError("Could not save the private configuration {}: {}".format(config_path, e))
|
||||
|
||||
@property
|
||||
def ram(self):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user