mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 17:28:08 +00:00
Have TraceNG start without needing cmd.exe
This commit is contained in:
parent
a4626a2b79
commit
8e695c8af1
@ -57,7 +57,7 @@ class TraceNGVM(BaseNode):
|
|||||||
|
|
||||||
def __init__(self, name, node_id, project, manager, console=None):
|
def __init__(self, name, node_id, project, manager, console=None):
|
||||||
|
|
||||||
super().__init__(name, node_id, project, manager, console=console, wrap_console=True)
|
super().__init__(name, node_id, project, manager, console=console)
|
||||||
self._process = None
|
self._process = None
|
||||||
self._started = False
|
self._started = False
|
||||||
self._traceng_stdout_file = ""
|
self._traceng_stdout_file = ""
|
||||||
@ -151,24 +151,16 @@ class TraceNGVM(BaseNode):
|
|||||||
log.info("Starting TraceNG: {}".format(command))
|
log.info("Starting TraceNG: {}".format(command))
|
||||||
self._traceng_stdout_file = os.path.join(self.working_dir, "traceng.log")
|
self._traceng_stdout_file = os.path.join(self.working_dir, "traceng.log")
|
||||||
log.info("Logging to {}".format(self._traceng_stdout_file))
|
log.info("Logging to {}".format(self._traceng_stdout_file))
|
||||||
flags = 0
|
flags = subprocess.CREATE_NEW_CONSOLE
|
||||||
#if sys.platform.startswith("win32"):
|
|
||||||
# flags = subprocess.CREATE_NEW_PROCESS_GROUP
|
|
||||||
with open(self._traceng_stdout_file, "w", encoding="utf-8") as fd:
|
|
||||||
self.command_line = ' '.join(command)
|
self.command_line = ' '.join(command)
|
||||||
self._process = yield from asyncio.create_subprocess_exec(*command,
|
self._process = yield from asyncio.create_subprocess_exec(*command,
|
||||||
stdout=fd,
|
|
||||||
stderr=subprocess.STDOUT,
|
|
||||||
cwd=self.working_dir,
|
cwd=self.working_dir,
|
||||||
creationflags=flags)
|
creationflags=flags)
|
||||||
monitor_process(self._process, self._termination_callback)
|
monitor_process(self._process, self._termination_callback)
|
||||||
|
|
||||||
yield from self._start_ubridge()
|
yield from self._start_ubridge()
|
||||||
if nio:
|
if nio:
|
||||||
yield from self.add_ubridge_udp_connection("TraceNG-{}".format(self._id), self._local_udp_tunnel[1], nio)
|
yield from self.add_ubridge_udp_connection("TraceNG-{}".format(self._id), self._local_udp_tunnel[1], nio)
|
||||||
|
|
||||||
yield from self.start_wrap_console()
|
|
||||||
|
|
||||||
log.info("TraceNG instance {} started PID={}".format(self.name, self._process.pid))
|
log.info("TraceNG instance {} started PID={}".format(self.name, self._process.pid))
|
||||||
self._started = True
|
self._started = True
|
||||||
self.status = "started"
|
self.status = "started"
|
||||||
@ -232,9 +224,6 @@ class TraceNGVM(BaseNode):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
log.info("Stopping TraceNG instance {} PID={}".format(self.name, self._process.pid))
|
log.info("Stopping TraceNG instance {} PID={}".format(self.name, self._process.pid))
|
||||||
#if sys.platform.startswith("win32"):
|
|
||||||
# self._process.send_signal(signal.CTRL_BREAK_EVENT)
|
|
||||||
#else:
|
|
||||||
try:
|
try:
|
||||||
self._process.terminate()
|
self._process.terminate()
|
||||||
# Sometime the process may already be dead when we garbage collect
|
# Sometime the process may already be dead when we garbage collect
|
||||||
@ -391,24 +380,18 @@ class TraceNGVM(BaseNode):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
command = [self._traceng_path()]
|
command = [self._traceng_path()]
|
||||||
|
|
||||||
# TODO: remove when testing with executable
|
|
||||||
command.extend(["-p", str(self._internal_console_port)]) # listen to console port
|
|
||||||
command.extend(["-m", "1"]) # the unique ID is used to set the MAC address offset
|
|
||||||
command.extend(["-i", "1"]) # option to start only one VPC instance
|
|
||||||
command.extend(["-F"]) # option to avoid the daemonization of VPCS
|
|
||||||
|
|
||||||
# use the local UDP tunnel to uBridge instead
|
# use the local UDP tunnel to uBridge instead
|
||||||
if not self._local_udp_tunnel:
|
if not self._local_udp_tunnel:
|
||||||
self._local_udp_tunnel = self._create_local_udp_tunnel()
|
self._local_udp_tunnel = self._create_local_udp_tunnel()
|
||||||
nio = self._local_udp_tunnel[0]
|
nio = self._local_udp_tunnel[0]
|
||||||
if nio and isinstance(nio, NIOUDP):
|
if nio and isinstance(nio, NIOUDP):
|
||||||
# UDP tunnel
|
# UDP tunnel
|
||||||
command.extend(["-s", str(nio.lport)]) # source UDP port
|
command.extend(["-c", str(nio.lport)]) # source UDP port
|
||||||
command.extend(["-c", str(nio.rport)]) # destination UDP port
|
command.extend(["-v", str(nio.rport)]) # destination UDP port
|
||||||
try:
|
try:
|
||||||
command.extend(["-t", socket.gethostbyname(nio.rhost)]) # destination host, we need to resolve the hostname because TraceNG doesn't support it
|
command.extend(["-b", socket.gethostbyname(nio.rhost)]) # destination host, we need to resolve the hostname because TraceNG doesn't support it
|
||||||
except socket.gaierror as e:
|
except socket.gaierror as e:
|
||||||
raise TraceNGError("Can't resolve hostname {}: {}".format(nio.rhost, e))
|
raise TraceNGError("Can't resolve hostname {}: {}".format(nio.rhost, e))
|
||||||
|
|
||||||
|
#command.extend(["10.0.0.1"]) # TODO: remove
|
||||||
return command
|
return command
|
||||||
|
Loading…
Reference in New Issue
Block a user