mirror of
https://github.com/GNS3/gns3-server
synced 2025-01-11 16:41:04 +00:00
Fixes Telnet server initialization issue in VirtualBox. Fixes #88.
This commit is contained in:
parent
a64dfdd694
commit
18f3859e87
@ -43,6 +43,7 @@ class TelnetServer(threading.Thread):
|
|||||||
|
|
||||||
def __init__(self, vm_name, pipe_path, host, port):
|
def __init__(self, vm_name, pipe_path, host, port):
|
||||||
|
|
||||||
|
threading.Thread.__init__(self)
|
||||||
self._vm_name = vm_name
|
self._vm_name = vm_name
|
||||||
self._pipe = pipe_path
|
self._pipe = pipe_path
|
||||||
self._host = host
|
self._host = host
|
||||||
@ -58,20 +59,15 @@ class TelnetServer(threading.Thread):
|
|||||||
# we must a thread for reading the pipe on Windows because it is a Named Pipe and it cannot be monitored by select()
|
# we must a thread for reading the pipe on Windows because it is a Named Pipe and it cannot be monitored by select()
|
||||||
self._use_thread = True
|
self._use_thread = True
|
||||||
|
|
||||||
try:
|
if ":" in self._host:
|
||||||
if ":" in self._host:
|
# IPv6 address support
|
||||||
# IPv6 address support
|
self._server_socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
|
||||||
self._server_socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
|
else:
|
||||||
else:
|
self._server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
self._server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
self._server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
self._server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
self._server_socket.bind((self._host, self._port))
|
||||||
self._server_socket.bind((self._host, self._port))
|
self._server_socket.listen(socket.SOMAXCONN)
|
||||||
self._server_socket.listen(socket.SOMAXCONN)
|
|
||||||
except OSError as e:
|
|
||||||
log.critical("unable to create a server socket: {}".format(e))
|
|
||||||
return
|
|
||||||
|
|
||||||
threading.Thread.__init__(self)
|
|
||||||
log.info("Telnet server initialized, waiting for clients on {}:{}".format(self._host, self._port))
|
log.info("Telnet server initialized, waiting for clients on {}:{}".format(self._host, self._port))
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
@ -711,7 +711,10 @@ class VirtualBoxVM(BaseVM):
|
|||||||
self._serial_pipe = open(pipe_name, "a+b")
|
self._serial_pipe = open(pipe_name, "a+b")
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
raise VirtualBoxError("Could not open the pipe {}: {}".format(pipe_name, e))
|
raise VirtualBoxError("Could not open the pipe {}: {}".format(pipe_name, e))
|
||||||
self._telnet_server_thread = TelnetServer(self._vmname, msvcrt.get_osfhandle(self._serial_pipe.fileno()), self._manager.port_manager.console_host, self._console)
|
try:
|
||||||
|
self._telnet_server_thread = TelnetServer(self._vmname, msvcrt.get_osfhandle(self._serial_pipe.fileno()), self._manager.port_manager.console_host, self._console)
|
||||||
|
except OSError as e:
|
||||||
|
raise VirtualBoxError("Unable to create Telnet server: {}".format(e))
|
||||||
self._telnet_server_thread.start()
|
self._telnet_server_thread.start()
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
@ -719,7 +722,10 @@ class VirtualBoxVM(BaseVM):
|
|||||||
self._serial_pipe.connect(pipe_name)
|
self._serial_pipe.connect(pipe_name)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
raise VirtualBoxError("Could not connect to the pipe {}: {}".format(pipe_name, e))
|
raise VirtualBoxError("Could not connect to the pipe {}: {}".format(pipe_name, e))
|
||||||
self._telnet_server_thread = TelnetServer(self._vmname, self._serial_pipe, self._manager.port_manager.console_host, self._console)
|
try:
|
||||||
|
self._telnet_server_thread = TelnetServer(self._vmname, self._serial_pipe, self._manager.port_manager.console_host, self._console)
|
||||||
|
except OSError as e:
|
||||||
|
raise VirtualBoxError("Unable to create Telnet server: {}".format(e))
|
||||||
self._telnet_server_thread.start()
|
self._telnet_server_thread.start()
|
||||||
|
|
||||||
def _stop_remote_console(self):
|
def _stop_remote_console(self):
|
||||||
@ -728,14 +734,15 @@ class VirtualBoxVM(BaseVM):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
if self._telnet_server_thread:
|
if self._telnet_server_thread:
|
||||||
self._telnet_server_thread.stop()
|
if self._telnet_server_thread.is_alive():
|
||||||
self._telnet_server_thread.join(timeout=3)
|
self._telnet_server_thread.stop()
|
||||||
if self._telnet_server_thread.isAlive():
|
self._telnet_server_thread.join(timeout=3)
|
||||||
|
if self._telnet_server_thread.is_alive():
|
||||||
log.warn("Serial pipe thread is still alive!")
|
log.warn("Serial pipe thread is still alive!")
|
||||||
self._telnet_server_thread = None
|
self._telnet_server_thread = None
|
||||||
|
|
||||||
if self._serial_pipe:
|
if self._serial_pipe:
|
||||||
if sys.platform.startswith('win'):
|
if sys.platform.startswith("win"):
|
||||||
win32file.CloseHandle(msvcrt.get_osfhandle(self._serial_pipe.fileno()))
|
win32file.CloseHandle(msvcrt.get_osfhandle(self._serial_pipe.fileno()))
|
||||||
else:
|
else:
|
||||||
self._serial_pipe.close()
|
self._serial_pipe.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user