mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Change address/host binding implementation.
This commit is contained in:
1 parent
862448ada1
commit
3edbdbe0b5
6 files changed
+35
-17
No files matched your search
@@ -47,8 +47,8 @@ class IModule(multiprocessing.Process):
|
||||
self._context = None
|
||||
self._ioloop = None
|
||||
self._stream = None
|
||||
self._host = args[0]
|
||||
self._port = args[1]
|
||||
self._zmq_host = args[0] # ZeroMQ server address
|
||||
self._zmq_port = args[1] # ZeroMQ server port
|
||||
self._current_session = None
|
||||
self._current_destination = None
|
||||
self._current_call_id = None
|
||||
@@ -60,7 +60,7 @@ class IModule(multiprocessing.Process):
|
||||
|
||||
self._context = zmq.Context()
|
||||
self._ioloop = zmq.eventloop.ioloop.IOLoop.instance()
|
||||
self._stream = self._create_stream(self._host, self._port, self._decode_request)
|
||||
self._stream = self._create_stream(self._zmq_host, self._zmq_port, self._decode_request)
|
||||
|
||||
def _create_stream(self, host=None, port=0, callback=None):
|
||||
"""
|
||||
|
||||
@@ -115,7 +115,7 @@ class Dynamips(IModule):
|
||||
self._tempdir = kwargs["temp_dir"]
|
||||
self._working_dir = self._projects_dir
|
||||
self._dynamips = ""
|
||||
self._default_host = "127.0.0.1"
|
||||
self._host = kwargs["host"]
|
||||
|
||||
if not sys.platform.startswith("win32"):
|
||||
#FIXME: pickle issues Windows
|
||||
@@ -216,7 +216,7 @@ class Dynamips(IModule):
|
||||
raise DynamipsError("Cannot write to working directory {}".format(self._working_dir))
|
||||
|
||||
log.info("starting the hypervisor manager with Dynamips working directory set to '{}'".format(self._working_dir))
|
||||
self._hypervisor_manager = HypervisorManager(self._dynamips, self._working_dir, self._default_host)
|
||||
self._hypervisor_manager = HypervisorManager(self._dynamips, self._working_dir, self._host)
|
||||
|
||||
for name, value in self._hypervisor_manager_settings.items():
|
||||
if hasattr(self._hypervisor_manager, name) and getattr(self._hypervisor_manager, name) != value:
|
||||
|
||||
@@ -67,8 +67,17 @@ class DynamipsHypervisor(object):
|
||||
Connects to the hypervisor.
|
||||
"""
|
||||
|
||||
# connect to a local address by default
|
||||
# if listening to all addresses (IPv4 or IPv6)
|
||||
if self._host == "0.0.0.0":
|
||||
host = "127.0.0.1"
|
||||
elif self._host == "::":
|
||||
host = "::1"
|
||||
else:
|
||||
host = self._host
|
||||
|
||||
try:
|
||||
self._socket = socket.create_connection((self._host,
|
||||
self._socket = socket.create_connection((host,
|
||||
self._port),
|
||||
self._timeout)
|
||||
except OSError as e:
|
||||
|
||||
@@ -406,6 +406,13 @@ class HypervisorManager(object):
|
||||
:param timeout: timeout value (default is 10 seconds)
|
||||
"""
|
||||
|
||||
# connect to a local address by default
|
||||
# if listening to all addresses (IPv4 or IPv6)
|
||||
if host == "0.0.0.0":
|
||||
host = "127.0.0.1"
|
||||
elif host == "::":
|
||||
host = "::1"
|
||||
|
||||
connection_success = False
|
||||
begin = time.time()
|
||||
# try to connect for 10 seconds
|
||||
@@ -423,7 +430,7 @@ class HypervisorManager(object):
|
||||
if not connection_success:
|
||||
# FIXME: throw exception here
|
||||
log.critical("Couldn't connect to hypervisor on {}:{} :{}".format(host, port,
|
||||
last_exception))
|
||||
last_exception))
|
||||
else:
|
||||
log.info("Dynamips server ready after {:.4f} seconds".format(time.time() - begin))
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ class IOU(IModule):
|
||||
self._udp_start_port_range = 30001
|
||||
self._udp_end_port_range = 40001
|
||||
self._current_udp_port = self._udp_start_port_range
|
||||
self._default_host = "0.0.0.0"
|
||||
self._host = kwargs["host"]
|
||||
self._projects_dir = os.path.join(kwargs["projects_dir"], "iou")
|
||||
self._tempdir = kwargs["temp_dir"]
|
||||
self._working_dir = self._projects_dir
|
||||
@@ -252,11 +252,11 @@ class IOU(IModule):
|
||||
except OSError as e:
|
||||
raise IOUError("Could not create working directory {}".format(e))
|
||||
|
||||
iou_instance = IOUDevice(iou_path, self._working_dir, host=self._default_host, name=name)
|
||||
iou_instance = IOUDevice(iou_path, self._working_dir, host=self._host, name=name)
|
||||
# find a console port
|
||||
if self._current_console_port >= self._console_end_port_range:
|
||||
self._current_console_port = self._console_start_port_range
|
||||
iou_instance.console = IOUDevice.find_unused_port(self._current_console_port, self._console_end_port_range, self._default_host)
|
||||
iou_instance.console = IOUDevice.find_unused_port(self._current_console_port, self._console_end_port_range, self._host)
|
||||
self._current_console_port += 1
|
||||
except IOUError as e:
|
||||
self.send_custom_error(str(e))
|
||||
@@ -479,13 +479,13 @@ class IOU(IModule):
|
||||
# find a UDP port
|
||||
if self._current_udp_port >= self._udp_end_port_range:
|
||||
self._current_udp_port = self._udp_start_port_range
|
||||
port = IOUDevice.find_unused_port(self._current_udp_port, self._udp_end_port_range, host=self._default_host, socket_type="UDP")
|
||||
port = IOUDevice.find_unused_port(self._current_udp_port, self._udp_end_port_range, host=self._host, socket_type="UDP")
|
||||
self._current_udp_port += 1
|
||||
|
||||
log.info("{} [id={}] has allocated UDP port {} with host {}".format(iou_instance .name,
|
||||
iou_instance .id,
|
||||
port,
|
||||
self._default_host))
|
||||
self._host))
|
||||
response = {"lport": port}
|
||||
|
||||
except IOUError as e:
|
||||
|
||||
Reference in new issue
Block a user