1 from django.http import HttpResponse
3 from manifold.core.query import Query
4 from manifoldapi.manifoldapi import execute_admin_query
6 def dispatch(request, action):
11 if request.method == 'POST':
12 req_items = request.POST
13 elif request.method == 'GET':
14 req_items = request.GET
16 for el in req_items.items():
17 if el[0].startswith('slice_hrn'):
19 elif el[0].startswith('initscript_code'):
20 initscript_code = el[1]
22 if (action == 'get') :
23 # select initscript_code from initscript where slice_hrn=='onelab.upmc.express'
24 query = Query.get('initscript').filter_by('slice_hrn', '==', slice_hrn).select('initscript_code')
25 results = execute_admin_query(request, query)
27 if (action == 'update') :
28 # UPDATE initscript SET initscript_code='test3' where slice_hrn=='onelab.upmc.express'
29 params = {'initscript_code' : initscript_code}
30 query = Query.update('initscript').filter_by('slice_hrn', '==', slice_hrn).set(params)
31 results = execute_admin_query(request, query)
33 if results[0]['initscript_code']==1:
34 results[0]['initscript_code']=initscript_code
36 error = "Error in update return value"
38 if (action == 'delete') :
39 # delete from initscript where slice_hrn=='onelab.upmc.express'
40 query = Query.delete('initscript').filter_by('slice_hrn', '==', slice_hrn)
41 results = execute_admin_query(request, query)
43 if results[0]['initscript_code']==1:
44 results[0]['initscript_code']=""
46 error = "Error in delete return value"
49 #print "Exception : ",e
51 ret = { "ret" : 1, "error" : error }
53 ret = { "ret" : 1, "slice_hrn" : slice_hrn }
55 ret = { "ret" : 0, "slice_hrn" : slice_hrn }
56 ret.update(results[0])
58 return HttpResponse(json.dumps(ret), content_type="application/json")