X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=manifoldapi%2Fmanifoldproxy.py;h=9385bfa3538e8a7f97cd0887cf7164be1d37995a;hb=5976423e0a726cb636a67bd77d61c8f36b23e7ce;hp=c16ffdee6590f06968c82ca106659df3a04e0708;hpb=3dbd8f411705ccb59e4fa7508794c970daca3c9d;p=unfold.git diff --git a/manifoldapi/manifoldproxy.py b/manifoldapi/manifoldproxy.py index c16ffdee..9385bfa3 100644 --- a/manifoldapi/manifoldproxy.py +++ b/manifoldapi/manifoldproxy.py @@ -13,6 +13,9 @@ from manifoldresult import ManifoldException from manifold.util.log import Log from myslice.configengine import ConfigEngine +# register activity +import activity.slice + debug=False #debug=True @@ -40,7 +43,7 @@ with the query passed using POST""" # format_out: how to serve the results if format != 'json': print "manifoldproxy.proxy: unexpected format %s -- exiting"%format - return + return HttpResponse ({"ret":0}, mimetype="application/json") try: # translate incoming POST request into a query object if debug: print 'manifoldproxy.proxy: request.POST',request.POST @@ -55,9 +58,13 @@ with the query passed using POST""" admin_user, admin_password = ConfigEngine().manifold_admin_user_password() manifold_api_session_auth = {'AuthMethod': 'password', 'Username': admin_user, 'AuthString': admin_password} else: - print request.session['manifold'] - manifold_api_session_auth = request.session['manifold']['auth'] - + if 'manifold' in request.session: + print '===> manifoldproxy.proxy: before auth', manifold_query + manifold_api_session_auth = request.session['manifold']['auth'] + else: + json_answer=json.dumps({'code':0,'value':[]}) + return HttpResponse (json_answer, mimetype="application/json") + if debug_empty and manifold_query.action.lower()=='get': json_answer=json.dumps({'code':0,'value':[]}) print "By-passing : debug_empty & 'get' request : returning a fake empty list" @@ -75,7 +82,26 @@ with the query passed using POST""" if 'description' in result and result['description'] \ and isinstance(result['description'], (tuple, list, set, frozenset)): result [ 'description' ] = [ ResultValue.to_html (x) for x in result['description'] ] - + + print "=> MANIFOLD PROXY executing: " + manifold_query.action.lower() + # + # register activity + # + # resource reservation + if (manifold_query.action.lower() == 'update') : + print result['value'][0] + if 'resource' in result['value'][0] : + for resource in result['value'][0]['resource'] : + activity.slice.resource(request, + { + 'slice' : result['value'][0]['slice_hrn'], + 'resource' : resource['hostname'], + 'resource_type' : resource['type'], + 'facility' : resource['facility_name'], + 'testbed' : resource['testbed_name'] + } + ) + json_answer=json.dumps(result) return HttpResponse (json_answer, mimetype="application/json") @@ -84,6 +110,7 @@ with the query passed using POST""" print "** PROXY ERROR **",e import traceback traceback.print_exc() + return HttpResponse ({"ret":0}, mimetype="application/json") #################### # see CSRF_FAILURE_VIEW in settings.py