mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Merge branch '1.5' into 2.0
This commit is contained in:
10 files changed
+69
-32
No files matched your search
@@ -602,8 +602,8 @@ class Dynamips(BaseManager):
|
||||
elif 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)
|
||||
# An empty startup config crash dynamips
|
||||
else:
|
||||
elif os.path.isfile(default_startup_config_path) and os.path.getsize(default_startup_config_path) == 0:
|
||||
# An empty startup-config may crash Dynamips
|
||||
startup_config_path = self._create_config(vm, default_startup_config_path, "!\n")
|
||||
yield from vm.set_configs(startup_config_path)
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
Represents a Dynamips hypervisor and starts/stops the associated Dynamips process.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import subprocess
|
||||
import asyncio
|
||||
@@ -117,6 +118,12 @@ class Hypervisor(DynamipsHypervisor):
|
||||
"""
|
||||
|
||||
self._command = self._build_command()
|
||||
env = os.environ.copy()
|
||||
if sys.platform.startswith("win"):
|
||||
# add the Npcap directory to $PATH to force Dynamips to use npcap DLL instead of Winpcap (if installed)
|
||||
system_root = os.path.join(os.path.expandvars("%SystemRoot%"), "System32", "Npcap")
|
||||
if os.path.isdir(system_root):
|
||||
env["PATH"] = system_root + ';' + env["PATH"]
|
||||
try:
|
||||
log.info("Starting Dynamips: {}".format(self._command))
|
||||
self._stdout_file = os.path.join(self.working_dir, "dynamips_i{}_stdout.txt".format(self._id))
|
||||
@@ -125,7 +132,8 @@ class Hypervisor(DynamipsHypervisor):
|
||||
self._process = yield from asyncio.create_subprocess_exec(*self._command,
|
||||
stdout=fd,
|
||||
stderr=subprocess.STDOUT,
|
||||
cwd=self._working_dir)
|
||||
cwd=self._working_dir,
|
||||
env=env)
|
||||
log.info("Dynamips process started PID={}".format(self._process.pid))
|
||||
self._started = True
|
||||
except (OSError, subprocess.SubprocessError) as e:
|
||||
|
||||
@@ -272,7 +272,10 @@ class Router(BaseNode):
|
||||
|
||||
status = yield from self.get_status()
|
||||
if status != "inactive":
|
||||
yield from self._hypervisor.send('vm stop "{name}"'.format(name=self._name))
|
||||
try:
|
||||
yield from self._hypervisor.send('vm stop "{name}"'.format(name=self._name))
|
||||
except DynamipsError as e:
|
||||
log.warn("Could not stop {}: {}".format(self._name, e))
|
||||
self.status = "stopped"
|
||||
log.info('Router "{name}" [{id}] has been stopped'.format(name=self._name, id=self._id))
|
||||
yield from self.save_configs()
|
||||
@@ -338,8 +341,8 @@ class Router(BaseNode):
|
||||
try:
|
||||
yield from self.stop()
|
||||
yield from self._hypervisor.send('vm delete "{}"'.format(self._name))
|
||||
except DynamipsError:
|
||||
pass
|
||||
except DynamipsError as e:
|
||||
log.warn("Could not stop and delete {}: {}".format(self._name, e))
|
||||
yield from self.hypervisor.stop()
|
||||
|
||||
if self._auto_delete_disks:
|
||||
@@ -1533,7 +1536,6 @@ class Router(BaseNode):
|
||||
if startup_config_base64:
|
||||
if not self.startup_config:
|
||||
self._startup_config = os.path.join("configs", "i{}_startup-config.cfg".format(self._dynamips_id))
|
||||
|
||||
try:
|
||||
config = base64.b64decode(startup_config_base64).decode("utf-8", errors="replace")
|
||||
config = "!\n" + config.replace("\r", "")
|
||||
@@ -1544,13 +1546,11 @@ class Router(BaseNode):
|
||||
except (binascii.Error, OSError) as e:
|
||||
raise DynamipsError("Could not save the startup configuration {}: {}".format(config_path, e))
|
||||
|
||||
if private_config_base64:
|
||||
if private_config_base64 and base64.b64decode(private_config_base64) != b'\nkerberos password \nend\n':
|
||||
if not self.private_config:
|
||||
self._private_config = os.path.join("configs", "i{}_private-config.cfg".format(self._dynamips_id))
|
||||
|
||||
try:
|
||||
config = base64.b64decode(private_config_base64).decode("utf-8", errors="replace")
|
||||
config = "!\n" + config.replace("\r", "")
|
||||
config_path = os.path.join(module_workdir, self.private_config)
|
||||
with open(config_path, "wb") as f:
|
||||
log.info("saving private-config to {}".format(self.private_config))
|
||||
|
||||
Reference in new issue
Block a user