1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

Fixes issues with VirtualBox Telnet server on Windows.

This commit is contained in:
grossmj 2014-11-02 18:06:15 -07:00
parent 393a312e7e
commit 087f0e82de
2 changed files with 10 additions and 7 deletions

View File

@ -180,7 +180,7 @@ class TelnetServer(threading.Thread):
if num_avail > 0: if num_avail > 0:
(error_code, output) = win32file.ReadFile(self._pipe, num_avail, None) (error_code, output) = win32file.ReadFile(self._pipe, num_avail, None)
return output return output
return "" return b""
else: else:
return self._pipe.recv(1024) return self._pipe.recv(1024)
@ -194,7 +194,7 @@ class TelnetServer(threading.Thread):
try: try:
data = self._read_from_pipe() data = self._read_from_pipe()
if not data and not sys.platform.startswith('win'): if not data and not sys.platform.startswith('win'):
log.debug("pipe has been closed!") log.debug("pipe has been closed! (no data)")
break break
self._write_lock.acquire() self._write_lock.acquire()
try: try:
@ -205,8 +205,8 @@ class TelnetServer(threading.Thread):
if sys.platform.startswith('win'): if sys.platform.startswith('win'):
# sleep every 10 ms # sleep every 10 ms
time.sleep(0.01) time.sleep(0.01)
except Exception: except Exception as e:
log.debug("pipe has been closed!") log.debug("pipe has been closed! {}".format(e))
break break
log.debug("reader thread exited") log.debug("reader thread exited")
self.stop() self.stop()
@ -325,7 +325,7 @@ class TelnetClient(object):
""" """
try: try:
buf = self._sock.recv(1024, socket.MSG_DONTWAIT) buf = self._sock.recv(1024)
except BlockingIOError: except BlockingIOError:
return None return None
except ConnectionResetError: except ConnectionResetError:
@ -419,10 +419,10 @@ class TelnetClient(object):
if __name__ == '__main__': if __name__ == '__main__':
log.setLevel(logging.INFO) logging.basicConfig(level=logging.INFO)
if sys.platform.startswith('win'): if sys.platform.startswith('win'):
import msvcrt import msvcrt
pipe_name = r'\\.\pipe\VBOX\Linux_Microcore_3.8.2' pipe_name = r'\\.\pipe\VBOX\Linux_Microcore_4.7.1'
pipe = open(pipe_name, 'a+b') pipe = open(pipe_name, 'a+b')
telnet_server = TelnetServer("VBOX", msvcrt.get_osfhandle(pipe.fileno()), "127.0.0.1", 3900) telnet_server = TelnetServer("VBOX", msvcrt.get_osfhandle(pipe.fileno()), "127.0.0.1", 3900)
else: else:

View File

@ -642,10 +642,12 @@ class VirtualBoxVM(object):
self._modify_vm("--nictracefile{} {}".format(adapter_id + 1, nio.pcap_output_file)) self._modify_vm("--nictracefile{} {}".format(adapter_id + 1, nio.pcap_output_file))
else: else:
# shutting down unused adapters... # shutting down unused adapters...
self._modify_vm("--cableconnected{} off".format(adapter_id + 1))
self._modify_vm("--nic{} null".format(adapter_id + 1)) self._modify_vm("--nic{} null".format(adapter_id + 1))
for adapter_id in range(len(self._ethernet_adapters), self._maximum_adapters): for adapter_id in range(len(self._ethernet_adapters), self._maximum_adapters):
log.debug("disabling remaining adapter {}".format(adapter_id)) log.debug("disabling remaining adapter {}".format(adapter_id))
self._modify_vm("--cableconnected{} off".format(adapter_id + 1))
self._modify_vm("--nic{} null".format(adapter_id + 1)) self._modify_vm("--nic{} null".format(adapter_id + 1))
def start(self): def start(self):
@ -727,6 +729,7 @@ class VirtualBoxVM(object):
if self._ethernet_adapters[adapter_id] is None: if self._ethernet_adapters[adapter_id] is None:
continue continue
self._modify_vm("--nictrace{} off".format(adapter_id + 1)) self._modify_vm("--nictrace{} off".format(adapter_id + 1))
self._modify_vm("--cableconnected{} off".format(adapter_id + 1))
self._modify_vm("--nic{} null".format(adapter_id + 1)) self._modify_vm("--nic{} null".format(adapter_id + 1))
def suspend(self): def suspend(self):