1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-23 23:38:21 +00:00

Fixes unicode decode error when saving IOS router configs. Fixes #115.

This commit is contained in:
grossmj 2015-03-28 18:09:53 -06:00
parent 3c917c59fb
commit 056ff14437
2 changed files with 13 additions and 12 deletions

View File

@ -356,13 +356,13 @@ class DynamipsVMHandler:
vm = dynamips_manager.get_vm(request.match_info["vm_id"],
project_id=request.match_info["project_id"])
startup_config, private_config = yield from vm.extract_config()
startup_config_base64, private_config_base64 = yield from vm.extract_config()
result = {}
if startup_config:
startup_config_content = base64.decodebytes(startup_config.encode("utf-8")).decode("utf-8")
if startup_config_base64:
startup_config_content = base64.b64decode(startup_config_base64).decode(errors='replace')
result["startup_config_content"] = startup_config_content
if private_config:
private_config_content = base64.decodebytes(private_config.encode("utf-8")).decode("utf-8")
if private_config_base64:
private_config_content = base64.b64decode(private_config_base64).decode(errors='replace')
result["private_config_content"] = private_config_content
response.set_status(200)

View File

@ -26,6 +26,7 @@ import sys
import os
import glob
import base64
import binascii
import logging
log = logging.getLogger(__name__)
@ -1183,8 +1184,7 @@ class Router(BaseVM):
slot_number=slot_number))
if adapter is None:
raise DynamipsError("Adapter is missing in {slot_number}".format( slot_number=slot_number))
raise DynamipsError("Adapter is missing in slot {slot_number}".format(slot_number=slot_number))
if not adapter.port_exists(port_number):
raise DynamipsError("Port {port_number} does not exist in adapter {adapter}".format(adapter=adapter,
@ -1221,7 +1221,8 @@ class Router(BaseVM):
raise DynamipsError('Slot {slot_number} does not exist on router "{name}"'.format(name=self._name,
slot_number=slot_number))
if adapter is None:
raise DynamipsError("Adapter is missing in slot {slot_number}".format(slot_number=slot_number))
if not adapter.port_exists(port_number):
raise DynamipsError("Port {port_number} does not exist in adapter {adapter}".format(adapter=adapter,
@ -1494,24 +1495,24 @@ class Router(BaseVM):
startup_config_base64, private_config_base64 = yield from self.extract_config()
if startup_config_base64:
try:
config = base64.decodebytes(startup_config_base64.encode("utf-8")).decode("utf-8")
config = base64.b64decode(startup_config_base64).decode(errors='replace')
config = "!\n" + config.replace("\r", "")
config_path = os.path.join(module_workdir, 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:
except (binascii.Error, 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 = base64.b64decode(private_config_base64).decode(errors='replace')
config = "!\n" + config.replace("\r", "")
config_path = os.path.join(module_workdir, 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:
except (binascii.Error, OSError) as e:
raise DynamipsError("Could not save the private configuration {}: {}".format(config_path, e))
def delete(self):