mirror of
https://github.com/GNS3/gns3-server.git
synced 2025-01-31 05:13:49 +02:00
Fixes bugs with IOS router configs. Fixes #354.
This commit is contained in:
parent
bebdadc465
commit
dd9f62158f
@ -367,15 +367,16 @@ class DynamipsVMHandler:
|
|||||||
else:
|
else:
|
||||||
# nvram doesn't contain anything if the router has not been started at least once
|
# nvram doesn't contain anything if the router has not been started at least once
|
||||||
# in this case just use the startup-config file
|
# in this case just use the startup-config file
|
||||||
startup_config_path = os.path.join(module_workdir, vm.startup_config)
|
if vm.startup_config:
|
||||||
if os.path.exists(startup_config_path):
|
startup_config_path = os.path.join(module_workdir, vm.startup_config)
|
||||||
try:
|
if os.path.isfile(startup_config_path):
|
||||||
with open(startup_config_path, "rb") as f:
|
try:
|
||||||
content = f.read().decode("utf-8", errors='replace')
|
with open(startup_config_path, "rb") as f:
|
||||||
if content:
|
content = f.read().decode("utf-8", errors='replace')
|
||||||
result["startup_config_content"] = content
|
if content:
|
||||||
except OSError as e:
|
result["startup_config_content"] = content
|
||||||
raise DynamipsError("Could not read the startup-config {}: {}".format(startup_config_path, e))
|
except OSError as e:
|
||||||
|
raise DynamipsError("Could not read the startup-config {}: {}".format(startup_config_path, e))
|
||||||
|
|
||||||
if private_config_base64:
|
if private_config_base64:
|
||||||
private_config_content = base64.b64decode(private_config_base64).decode("utf-8", errors='replace')
|
private_config_content = base64.b64decode(private_config_base64).decode("utf-8", errors='replace')
|
||||||
@ -383,15 +384,16 @@ class DynamipsVMHandler:
|
|||||||
else:
|
else:
|
||||||
# nvram doesn't contain anything if the router has not been started at least once
|
# nvram doesn't contain anything if the router has not been started at least once
|
||||||
# in this case just use the private-config file
|
# in this case just use the private-config file
|
||||||
private_config_path = os.path.join(module_workdir, vm.private_config)
|
if vm.private_config:
|
||||||
if os.path.exists(private_config_path):
|
private_config_path = os.path.join(module_workdir, vm.private_config)
|
||||||
try:
|
if os.path.isfile(private_config_path):
|
||||||
with open(private_config_path, "rb") as f:
|
try:
|
||||||
content = f.read().decode("utf-8", errors='replace')
|
with open(private_config_path, "rb") as f:
|
||||||
if content:
|
content = f.read().decode("utf-8", errors='replace')
|
||||||
result["private_config_content"] = content
|
if content:
|
||||||
except OSError as e:
|
result["private_config_content"] = content
|
||||||
raise DynamipsError("Could not read the private-config {}: {}".format(private_config_path, e))
|
except OSError as e:
|
||||||
|
raise DynamipsError("Could not read the private-config {}: {}".format(private_config_path, e))
|
||||||
|
|
||||||
response.set_status(200)
|
response.set_status(200)
|
||||||
response.json(result)
|
response.json(result)
|
||||||
|
@ -535,17 +535,19 @@ class Dynamips(BaseManager):
|
|||||||
default_private_config_path = os.path.join(module_workdir, "configs", "i{}_private-config.cfg".format(vm.dynamips_id))
|
default_private_config_path = os.path.join(module_workdir, "configs", "i{}_private-config.cfg".format(vm.dynamips_id))
|
||||||
|
|
||||||
startup_config_path = settings.get("startup_config")
|
startup_config_path = settings.get("startup_config")
|
||||||
|
startup_config_content = settings.get("startup_config_content")
|
||||||
if startup_config_path:
|
if startup_config_path:
|
||||||
yield from vm.set_configs(startup_config_path)
|
yield from vm.set_configs(startup_config_path)
|
||||||
else:
|
elif startup_config_content:
|
||||||
startup_config_path = self._create_config(vm, default_startup_config_path, settings.get("startup_config_content"))
|
startup_config_path = self._create_config(vm, default_startup_config_path, startup_config_content)
|
||||||
yield from vm.set_configs(startup_config_path)
|
yield from vm.set_configs(startup_config_path)
|
||||||
|
|
||||||
private_config_path = settings.get("private_config")
|
private_config_path = settings.get("private_config")
|
||||||
|
private_config_content = settings.get("private_config_content")
|
||||||
if private_config_path:
|
if private_config_path:
|
||||||
yield from vm.set_configs(vm.startup_config, private_config_path)
|
yield from vm.set_configs(vm.startup_config, private_config_path)
|
||||||
else:
|
elif private_config_content:
|
||||||
private_config_path = self._create_config(vm, default_private_config_path, settings.get("private_config_content"))
|
private_config_path = self._create_config(vm, default_private_config_path, private_config_content)
|
||||||
yield from vm.set_configs(vm.startup_config, private_config_path)
|
yield from vm.set_configs(vm.startup_config, private_config_path)
|
||||||
|
|
||||||
def _create_config(self, vm, path, content=None):
|
def _create_config(self, vm, path, content=None):
|
||||||
|
Loading…
Reference in New Issue
Block a user