2
0
mirror of https://github.com/xcat2/confluent.git synced 2025-04-15 09:39:37 +00:00

Add /nodes/<node>/forward/web

This facilitates GUI to launch web interface,
even if the target is unreachable.
This commit is contained in:
Jarrod Johnson 2017-09-22 13:53:37 -04:00
parent c571601a29
commit f44eb412c5
3 changed files with 24 additions and 2 deletions

View File

@ -211,6 +211,10 @@ def _init_core():
}),
},
},
#'forward': {
# # Another dummy value, currently only for the gui
# 'web': None,
#},
'health': {
'hardware': PluginRoute({
'pluginattrs': ['hardwaremanagement.method'],

View File

@ -50,7 +50,7 @@ def forward_port(sock, target):
def forward_video():
sock = eventlet.listen(('localhost', 3900, 0, 0), family=socket.AF_INET6)
sock = eventlet.listen(('::', 3900, 0, 0), family=socket.AF_INET6)
while True:
conn, _ = sock.accept()
if vidtarget is None:
@ -67,7 +67,7 @@ def get_port(addr):
global vidtarget
global vidforwarder
if addr not in forwarders:
newsock = eventlet.listen(('localhost', 0, 0, 0),
newsock = eventlet.listen(('::', 0, 0, 0),
family=socket.AF_INET6)
forwarders[addr] = newsock
sockhandler[newsock] = eventlet.spawn(forward_port, newsock, addr)

View File

@ -21,6 +21,7 @@ import Cookie
import confluent.auth as auth
import confluent.config.attributes as attribs
import confluent.consoleserver as consoleserver
import confluent.forwarder as forwarder
import confluent.exceptions as exc
import confluent.log as log
import confluent.messages
@ -446,6 +447,23 @@ def resourcehandler_backend(env, start_response):
start_response('{0} {1}'.format(e.apierrorcode, e.apierrorstr),
headers)
yield e.get_error_body()
elif (env['PATH_INFO'].endswith('/forward/web') and
env['PATH_INFO'].startswith('/nodes/')):
prefix, _, _ = env['PATH_INFO'].partition('/forward/web')
_, _, nodename = prefix.rpartition('/')
hm = cfgmgr.get_node_attributes(nodename, 'hardwaremanagement.manager')
targip = hm.get(nodename, {}).get(
'hardwaremanagement.manager', {}).get('value', None)
if not targip:
start_response('404 Not Found', headers)
yield 'No hardwaremanagemnet.manager defined for node'
return
funport = forwarder.get_port(targip)
host = env['HTTP_X_FORWARDED_HOST']
url = 'https://{0}:{1}/'.format(host, funport)
start_response('302', [('Location', url)])
yield 'Our princess is in another castle!'
return
elif (operation == 'create' and ('/console/session' in env['PATH_INFO'] or
'/shell/sessions/' in env['PATH_INFO'])):
#hard bake JSON into this path, do not support other incarnations