Fix SSL support for controller and local compute. Fixes #1826

This commit is contained in:
grossmj committed 2020-10-27 23:25:19 +10:30
1 parent 5dab0c2587
commit b6a021dabd
3 files changed
+26 -9

No files matched your search

+9 -2
View File
@@ -81,16 +81,23 @@ class Controller:
name = "Main server"
computes = self._load_controller_settings()
from gns3server.web.web_server import WebServer
ssl_context = WebServer.instance().ssl_context()
protocol = server_config.get("protocol", "http")
if ssl_context and protocol != "https":
log.warning("Protocol changed to 'https' for local compute because SSL is enabled".format(port))
protocol = "https"
try:
self._local_server = await self.add_compute(compute_id="local",
name=name,
protocol=server_config.get("protocol", "http"),
protocol=protocol,
host=host,
console_host=console_host,
port=port,
user=server_config.get("user", ""),
password=server_config.get("password", ""),
force=True)
force=True,
ssl_context=ssl_context)
except aiohttp.web.HTTPConflict:
log.fatal("Cannot access to the local server, make sure something else is not running on the TCP port {}".format(port))
sys.exit(1)
+6 -2
View File
@@ -57,7 +57,8 @@ class Compute:
A GNS3 compute.
"""
def __init__(self, compute_id, controller=None, protocol="http", host="localhost", port=3080, user=None, password=None, name=None, console_host=None):
def __init__(self, compute_id, controller=None, protocol="http", host="localhost",
port=3080, user=None, password=None, name=None, console_host=None, ssl_context=None):
self._http_session = None
assert controller is not None
log.info("Create compute %s", compute_id)
@@ -81,6 +82,7 @@ class Compute:
self._cpu_usage_percent = None
self._memory_usage_percent = None
self._last_error = None
self._ssl_context = ssl_context
self._capabilities = {
"version": None,
"node_types": []
@@ -92,7 +94,9 @@ class Compute:
def _session(self):
if self._http_session is None or self._http_session.closed is True:
self._http_session = aiohttp.ClientSession(connector=aiohttp.TCPConnector(limit=None, force_close=True))
self._http_session = aiohttp.ClientSession(connector=aiohttp.TCPConnector(limit=None,
force_close=True,
ssl_context=self._ssl_context))
return self._http_session
#def __del__(self):