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

Use a temporary file for Dynamips process logging (avoid Windows file

locking when saving to another location).
This commit is contained in:
grossmj 2014-04-09 18:39:24 -06:00
parent 2dc189c592
commit b614aa8290

View File

@ -22,6 +22,7 @@ Represents a Dynamips hypervisor and starts/stops the associated Dynamips proces
import os import os
import time import time
import subprocess import subprocess
import tempfile
from .dynamips_hypervisor import DynamipsHypervisor from .dynamips_hypervisor import DynamipsHypervisor
from .dynamips_error import DynamipsError from .dynamips_error import DynamipsError
@ -202,9 +203,9 @@ class Hypervisor(DynamipsHypervisor):
self._command = self._build_command() self._command = self._build_command()
try: try:
log.info("starting Dynamips: {}".format(self._command)) log.info("starting Dynamips: {}".format(self._command))
self._stdout_file = os.path.join(self._working_dir, "dynamips-{}.log".format(self._port)) with tempfile.NamedTemporaryFile(delete=False) as fd:
log.info("logging to {}".format(self._stdout_file)) self._stdout_file = fd.name
with open(self._stdout_file, "w") as fd: log.info("Dynamips process logging to {}".format(fd.name))
self._process = subprocess.Popen(self._command, self._process = subprocess.Popen(self._command,
stdout=fd, stdout=fd,
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
@ -234,6 +235,11 @@ class Hypervisor(DynamipsHypervisor):
if self._process.poll() == None: if self._process.poll() == None:
log.warn("Dynamips process {} is still running".format(self._process.pid)) log.warn("Dynamips process {} is still running".format(self._process.pid))
if self._stdout_file and os.access(self._stdout_file, os.W_OK):
try:
os.remove(self._stdout_file)
except OSError as e:
log.warning("could not delete temporary Dynamips log file: {}".format(e))
self._started = False self._started = False
def read_stdout(self): def read_stdout(self):
@ -243,7 +249,7 @@ class Hypervisor(DynamipsHypervisor):
""" """
output = "" output = ""
if self._stdout_file: 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) as file:
output = file.read() output = file.read()