1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 09:18:08 +00:00

Replace decode errors when reading device configs.

This commit is contained in:
grossmj 2014-05-29 12:59:13 -06:00
parent e817c13738
commit 61ef750da3
7 changed files with 11 additions and 11 deletions

View File

@ -474,7 +474,7 @@ class Dynamips(IModule):
raise DynamipsError("Could not create configs directory: {}".format(e)) raise DynamipsError("Could not create configs directory: {}".format(e))
try: try:
with open(local_base_config, "r") as f: with open(local_base_config, "r", errors="replace") as f:
config = f.read() config = f.read()
with open(config_path, "w") as f: with open(config_path, "w") as f:
config = "!\n" + config.replace("\r", "") config = "!\n" + config.replace("\r", "")

View File

@ -251,7 +251,7 @@ class Hypervisor(DynamipsHypervisor):
output = "" output = ""
if self._stdout_file and os.access(self._stdout_file, os.R_OK): if self._stdout_file and os.access(self._stdout_file, os.R_OK):
try: try:
with open(self._stdout_file) as file: with open(self._stdout_file, errors="replace") as file:
output = file.read() output = file.read()
except OSError as e: except OSError as e:
log.warn("could not read {}: {}".format(self._stdout_file, e)) log.warn("could not read {}: {}".format(self._stdout_file, e))

View File

@ -223,7 +223,7 @@ class Router(object):
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", "{}.cfg".format(self.name))
if os.path.isfile(startup_config_path): if os.path.isfile(startup_config_path):
try: try:
with open(startup_config_path, "r+") as f: with open(startup_config_path, "r+", errors="replace") as f:
old_config = f.read() old_config = f.read()
new_config = old_config.replace(self.name, new_name) new_config = old_config.replace(self.name, new_name)
f.seek(0) f.seek(0)
@ -239,7 +239,7 @@ class Router(object):
private_config_path = os.path.join(self.hypervisor.working_dir, "configs", "{}-private.cfg".format(self.name)) private_config_path = os.path.join(self.hypervisor.working_dir, "configs", "{}-private.cfg".format(self.name))
if os.path.isfile(private_config_path): if os.path.isfile(private_config_path):
try: try:
with open(private_config_path, "r+") as f: with open(private_config_path, "r+", errors="replace") as f:
old_config = f.read() old_config = f.read()
new_config = old_config.replace(self.name, new_name) new_config = old_config.replace(self.name, new_name)
f.seek(0) f.seek(0)

View File

@ -421,7 +421,7 @@ class IOU(IModule):
if os.path.isfile(request["startup_config"]) and request["startup_config"] != config_path: if os.path.isfile(request["startup_config"]) and request["startup_config"] != config_path:
# this is a local file set in the GUI # this is a local file set in the GUI
try: try:
with open(request["startup_config"], "r") as f: with open(request["startup_config"], "r", errors="replace") as f:
config = f.read() config = f.read()
with open(config_path, "w") as f: with open(config_path, "w") as f:
config = "!\n" + config.replace("\r", "") config = "!\n" + config.replace("\r", "")

View File

@ -188,7 +188,7 @@ class IOUDevice(object):
config_path = os.path.join(self._working_dir, "startup-config") config_path = os.path.join(self._working_dir, "startup-config")
if os.path.isfile(config_path): if os.path.isfile(config_path):
try: try:
with open(config_path, "r+") as f: with open(config_path, "r+", errors="replace") as f:
old_config = f.read() old_config = f.read()
new_config = old_config.replace(self._name, new_name) new_config = old_config.replace(self._name, new_name)
f.seek(0) f.seek(0)
@ -611,7 +611,7 @@ class IOUDevice(object):
output = "" output = ""
if self._iou_stdout_file: if self._iou_stdout_file:
try: try:
with open(self._iou_stdout_file) as file: with open(self._iou_stdout_file, errors="replace") as file:
output = file.read() output = file.read()
except OSError as e: except OSError as e:
log.warn("could not read {}: {}".format(self._iou_stdout_file, e)) log.warn("could not read {}: {}".format(self._iou_stdout_file, e))
@ -626,7 +626,7 @@ class IOUDevice(object):
output = "" output = ""
if self._iouyap_stdout_file: if self._iouyap_stdout_file:
try: try:
with open(self._iouyap_stdout_file) as file: with open(self._iouyap_stdout_file, errors="replace") as file:
output = file.read() output = file.read()
except OSError as e: except OSError as e:
log.warn("could not read {}: {}".format(self._iouyap_stdout_file, e)) log.warn("could not read {}: {}".format(self._iouyap_stdout_file, e))

View File

@ -336,7 +336,7 @@ class VPCS(IModule):
if os.path.isfile(request["script_file"]) and request["script_file"] != config_path: if os.path.isfile(request["script_file"]) and request["script_file"] != config_path:
# this is a local file set in the GUI # this is a local file set in the GUI
try: try:
with open(request["script_file"], "r") as f: with open(request["script_file"], "r", errors="replace") as f:
config = f.read() config = f.read()
with open(config_path, "w") as f: with open(config_path, "w") as f:
config = config.replace("\r", "") config = config.replace("\r", "")

View File

@ -170,7 +170,7 @@ class VPCSDevice(object):
config_path = os.path.join(self._working_dir, "startup.vpc") config_path = os.path.join(self._working_dir, "startup.vpc")
if os.path.isfile(config_path): if os.path.isfile(config_path):
try: try:
with open(config_path, "r+") as f: with open(config_path, "r+", errors="replace") as f:
old_config = f.read() old_config = f.read()
new_config = old_config.replace(self._name, new_name) new_config = old_config.replace(self._name, new_name)
f.seek(0) f.seek(0)
@ -388,7 +388,7 @@ class VPCSDevice(object):
output = "" output = ""
if self._vpcs_stdout_file: if self._vpcs_stdout_file:
try: try:
with open(self._vpcs_stdout_file) as file: with open(self._vpcs_stdout_file, errors="replace") as file:
output = file.read() output = file.read()
except OSError as e: except OSError as e:
log.warn("could not read {}: {}".format(self._vpcs_stdout_file, e)) log.warn("could not read {}: {}".format(self._vpcs_stdout_file, e))