From 49506ada3fe71ef8ffb6e75ec19c03a11cf782d6 Mon Sep 17 00:00:00 2001 From: grossmj Date: Wed, 18 Jun 2014 07:22:57 -0600 Subject: [PATCH] Fixes inconsistencies with startup and private config paths when renaming an IOS router. --- gns3server/modules/dynamips/backends/vm.py | 4 ++-- gns3server/modules/dynamips/nodes/router.py | 12 +++--------- gns3server/modules/iou/__init__.py | 2 +- gns3server/modules/iou/iou_device.py | 4 ++-- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/gns3server/modules/dynamips/backends/vm.py b/gns3server/modules/dynamips/backends/vm.py index c757c7b4..57d12a99 100644 --- a/gns3server/modules/dynamips/backends/vm.py +++ b/gns3server/modules/dynamips/backends/vm.py @@ -387,8 +387,8 @@ class VM(object): response = {} try: - startup_config_path = os.path.join(router.hypervisor.working_dir, "configs", "{}.cfg".format(router.name)) - private_config_path = os.path.join(router.hypervisor.working_dir, "configs", "{}-private.cfg".format(router.name)) + startup_config_path = os.path.join(router.hypervisor.working_dir, "configs", "i{}_startup-config.cfg".format(router.id)) + private_config_path = os.path.join(router.hypervisor.working_dir, "configs", "i{}_private-config.cfg".format(router.id)) # a new startup-config has been pushed if "startup_config_base64" in request: diff --git a/gns3server/modules/dynamips/nodes/router.py b/gns3server/modules/dynamips/nodes/router.py index 174a7136..6b8f9228 100644 --- a/gns3server/modules/dynamips/nodes/router.py +++ b/gns3server/modules/dynamips/nodes/router.py @@ -227,7 +227,7 @@ class Router(object): if self._startup_config: # change the hostname in the startup-config - startup_config_path = os.path.join(self.hypervisor.working_dir, "configs", "{}.cfg".format(self.name)) + startup_config_path = os.path.join(self.hypervisor.working_dir, "configs", "i{}_startup-config.cfg".format(self.id)) if os.path.isfile(startup_config_path): try: with open(startup_config_path, "r+", errors="replace") as f: @@ -235,15 +235,12 @@ class Router(object): new_config = old_config.replace(self.name, new_name) f.seek(0) f.write(new_config) - new_startup_config_path = os.path.join(os.path.dirname(startup_config_path), "{}.cfg".format(new_name)) - os.rename(startup_config_path, new_startup_config_path) except OSError as e: raise DynamipsError("Could not amend the configuration {}: {}".format(startup_config_path, e)) - self.set_config(new_startup_config_path) if self._private_config: - # change the hostname in the startup-config - private_config_path = os.path.join(self.hypervisor.working_dir, "configs", "{}-private.cfg".format(self.name)) + # change the hostname in the private-config + private_config_path = os.path.join(self.hypervisor.working_dir, "configs", "i{}_private-config.cfg".format(self.id)) if os.path.isfile(private_config_path): try: with open(private_config_path, "r+", errors="replace") as f: @@ -251,11 +248,8 @@ class Router(object): new_config = old_config.replace(self.name, new_name) f.seek(0) f.write(new_config) - new_private_config_path = os.path.join(os.path.dirname(private_config_path), "{}-private.cfg".format(new_name)) - os.rename(private_config_path, new_private_config_path) except OSError as e: raise DynamipsError("Could not amend the configuration {}: {}".format(private_config_path, e)) - self.set_config(self.startup_config, new_private_config_path) new_name = '"' + new_name + '"' # put the new name into quotes to protect spaces self._hypervisor.send("vm rename {name} {new_name}".format(name=self._name, diff --git a/gns3server/modules/iou/__init__.py b/gns3server/modules/iou/__init__.py index 7bdc7494..b42c8030 100644 --- a/gns3server/modules/iou/__init__.py +++ b/gns3server/modules/iou/__init__.py @@ -373,7 +373,7 @@ class IOU(IModule): if not iou_instance: return - config_path = os.path.join(iou_instance.working_dir, "initial-config") + config_path = os.path.join(iou_instance.working_dir, "initial-config.cfg") try: if "initial_config_base64" in request: # a new initial-config has been pushed diff --git a/gns3server/modules/iou/iou_device.py b/gns3server/modules/iou/iou_device.py index ca2f229f..44cf0831 100644 --- a/gns3server/modules/iou/iou_device.py +++ b/gns3server/modules/iou/iou_device.py @@ -208,9 +208,9 @@ class IOUDevice(object): new_working_dir, e)) - if self._intial_config: + if self._initial_config: # update the initial-config - config_path = os.path.join(self._working_dir, "initial-config") + config_path = os.path.join(self._working_dir, "initial-config.cfg") if os.path.isfile(config_path): try: with open(config_path, "r+", errors="replace") as f: