Amend device configs when renaming.

This commit is contained in:
grossmj committed 2014-05-19 13:14:57 -06:00
1 parent 7182e59892
commit babdfd5086
5 files changed
+76 -6

No files matched your search

+1 -1
View File
@@ -437,7 +437,7 @@ class IOU(IModule):
except OSError as e:
raise IOUError("Could not save the configuration from {} to {}: {}".format(request["startup_config"], config_path, e))
elif not os.path.isfile(config_path):
raise IOUError("Startup-config {} could not be found on this server".format(config_path))
raise IOUError("Startup-config {} could not be found on this server".format(request["startup_config"]))
except IOUError as e:
self.send_custom_error(str(e))
return
+14 -1
View File
@@ -177,10 +177,23 @@ class IOUDevice(object):
:param new_name: name
"""
self._name = new_name
if self._startup_config:
# update the startup-config
config_path = os.path.join(self.working_dir, "startup-config")
if os.path.isfile(config_path):
try:
with open(config_path, "r+") as f:
old_config = f.read()
new_config = old_config.replace(self._name, new_name)
f.seek(0)
f.write(new_config)
except OSError as e:
raise IOUError("Could not amend the configuration {}: {}".format(config_path, e))
log.info("IOU {name} [id={id}]: renamed to {new_name}".format(name=self._name,
id=self._id,
new_name=new_name))
self._name = new_name
@property
def path(self):