mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-11-16 16:54:51 +02:00
Support for web socket console over HTTPS
This commit is contained in:
parent
0f07b9e019
commit
3b22bcfe96
@ -487,11 +487,18 @@ class NodeHandler:
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
ws_console_compute_url = "ws://{compute_host}:{compute_port}/v2/compute/projects/{project_id}/{node_type}/nodes/{node_id}/console/ws".format(compute_host=compute_host,
|
ws_protocol = "ws"
|
||||||
compute_port=compute.port,
|
if request.scheme == "https":
|
||||||
project_id=project.id,
|
ws_protocol = "wss"
|
||||||
node_type=node.node_type,
|
|
||||||
node_id=node.id)
|
ws_console_compute_url = "{protocol}://{compute_host}:{compute_port}/v2/compute/projects/{project_id}/{node_type}/nodes/{node_id}/console/ws".format(
|
||||||
|
protocol=ws_protocol,
|
||||||
|
compute_host=compute_host,
|
||||||
|
compute_port=compute.port,
|
||||||
|
project_id=project.id,
|
||||||
|
node_type=node.node_type,
|
||||||
|
node_id=node.id
|
||||||
|
)
|
||||||
|
|
||||||
async def ws_forward(ws_client):
|
async def ws_forward(ws_client):
|
||||||
async for msg in ws:
|
async for msg in ws:
|
||||||
@ -504,7 +511,7 @@ class NodeHandler:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(limit=None, force_close=True)) as session:
|
async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(limit=None, force_close=True)) as session:
|
||||||
async with session.ws_connect(ws_console_compute_url) as ws_client:
|
async with session.ws_connect(ws_console_compute_url, ssl=False) as ws_client:
|
||||||
asyncio.ensure_future(ws_forward(ws_client))
|
asyncio.ensure_future(ws_forward(ws_client))
|
||||||
async for msg in ws_client:
|
async for msg in ws_client:
|
||||||
if msg.type == aiohttp.WSMsgType.TEXT:
|
if msg.type == aiohttp.WSMsgType.TEXT:
|
||||||
@ -515,6 +522,8 @@ class NodeHandler:
|
|||||||
break
|
break
|
||||||
except ConnectionResetError:
|
except ConnectionResetError:
|
||||||
log.info("Websocket console connection with compute disconnected")
|
log.info("Websocket console connection with compute disconnected")
|
||||||
|
except aiohttp.ClientError as e:
|
||||||
|
log.error("Websocket console connection with compute failed: {}".format(e))
|
||||||
finally:
|
finally:
|
||||||
if not ws.closed:
|
if not ws.closed:
|
||||||
await ws.close()
|
await ws.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user