mirror of
https://github.com/xcat2/confluent.git
synced 2024-11-22 17:43:14 +00:00
Convert wsgi function to be generator
Since wsgi function returns iterable, it turns out to be easy to do it this way. For now, hardcode json dumps, two things: 1: call out to module supporting HTML and JSON interpretation 2: in both cases, a header and footer must sandwich the responses in http In socketapi, responses will come back without a container, but http does not afford us such luxury. Create a containing json structure. On first iteration, do not prepend with ,. prepend with , all other times.
This commit is contained in:
parent
17603a59fd
commit
3d1e398977
@ -138,12 +138,14 @@ def resourcehandler(env, start_response):
|
||||
start_response('401 Authentication Required',
|
||||
[('Content-type', 'text/plain'),
|
||||
('WWW-Authenticate', 'Basic realm="confluent"')])
|
||||
return 'authentication required'
|
||||
yield 'authentication required'
|
||||
return
|
||||
if authorized['code'] == 403:
|
||||
start_response('403 Forbidden',
|
||||
[('Content-type', 'text/plain'),
|
||||
('WWW-Authenticate', 'Basic realm="confluent"')])
|
||||
return 'authorization failed'
|
||||
yield 'authorization failed'
|
||||
return
|
||||
if authorized['code'] != 200:
|
||||
raise Exception("Unrecognized code from auth engine")
|
||||
headers = [('Content-Type', 'application/json; charset=utf-8')]
|
||||
@ -164,7 +166,8 @@ def resourcehandler(env, start_response):
|
||||
return
|
||||
sessid = _assign_consessionid(consession)
|
||||
start_response('200 OK', headers)
|
||||
return ['{"session":"%s","data":""}' % sessid]
|
||||
yield '{"session":"%s","data":""}' % sessid
|
||||
return
|
||||
elif 'keys' in querydict.keys():
|
||||
# client wishes to push some keys into the remote console
|
||||
input = ""
|
||||
@ -174,7 +177,7 @@ def resourcehandler(env, start_response):
|
||||
consolesessions[sessid]['expiry'] = time.time() + 90
|
||||
consolesessions[sessid]['session'].write(input)
|
||||
start_response('200 OK', headers)
|
||||
return [] # client has requests to send or receive, not both...
|
||||
return # client has requests to send or receive, not both...
|
||||
else: #no keys, but a session, means it's hooking to receive data
|
||||
sessid = querydict['session']
|
||||
consolesessions[sessid]['expiry'] = time.time() + 90
|
||||
@ -186,11 +189,12 @@ def resourcehandler(env, start_response):
|
||||
except UnicodeDecodeError:
|
||||
rsp = json.dumps({'session': querydict['session'], 'data': 'DECODEERROR'})
|
||||
start_response('200 OK', headers)
|
||||
return [rsp]
|
||||
yield rsp
|
||||
return
|
||||
else:
|
||||
pluginapi.handle_path(env['PATH_INFO'], 'retrieve', cfgmgr)
|
||||
start_response('404 Not Found', headers)
|
||||
return ["404 Unrecognized resource"]
|
||||
start_response('200 OK', headers)
|
||||
for rsp in pluginapi.handle_path(env['PATH_INFO'], 'retrieve', cfgmgr):
|
||||
yield json.dumps(rsp, separators=(',', ':'))
|
||||
|
||||
|
||||
def serve():
|
||||
|
@ -174,20 +174,21 @@ class IpmiIterator(object):
|
||||
'secret.managementuser', 'secret.managementpassphrase',
|
||||
'hardwaremanagement.manager'])
|
||||
cfg.decrypt = crypt
|
||||
self.gpile = greenpool.GreenPile()
|
||||
for node in nodes:
|
||||
print IpmiHandler(operator, node, element, configdata).handle_request()
|
||||
#eventlet.spawn(perform_request,
|
||||
# (operator, node, element, configdata, self.resultqueue))
|
||||
self.gpile.spawn(perform_request, operator, node, element, configdata)
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def next(self):
|
||||
pass
|
||||
ndata = self.gpile.next()
|
||||
# need to apply any translations between pyghmi and confluent
|
||||
return ndata
|
||||
|
||||
|
||||
def perform_request(operator, node, element, configdata, queue):
|
||||
IpmiHandler(operator, node, element, configdata).handle_request()
|
||||
def perform_request(operator, node, element, configdata):
|
||||
return IpmiHandler(operator, node, element, configdata).handle_request()
|
||||
|
||||
|
||||
class IpmiHandler(object):
|
||||
|
Loading…
Reference in New Issue
Block a user