From fe9989408f034d3d5f26a4cc64425360866a97d1 Mon Sep 17 00:00:00 2001 From: Loic Baron Date: Thu, 15 Jan 2015 11:08:02 +0100 Subject: [PATCH] Initscripts: rest and url --- myslice/urls.py | 1 + rest/initscript.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 rest/initscript.py diff --git a/myslice/urls.py b/myslice/urls.py index 5f4c7d4f..d09f4807 100644 --- a/myslice/urls.py +++ b/myslice/urls.py @@ -91,6 +91,7 @@ urls = [ (r'^create/(?P[^/]+)/(?P[^/]+)?/?$', 'rest.create.dispatch'), (r'^delete/(?P[^/]+)/(?P[^/]+)?/?$', 'rest.delete.dispatch'), (r'^credentials/(?P[^/]+)/?$', 'rest.credentials.dispatch'), + (r'^initscript/(?P[^/]+)/?$', 'rest.initscript.dispatch'), # # REST monitoring (r'^monitor/services/?$', 'rest.monitor.servicesStatus'), diff --git a/rest/initscript.py b/rest/initscript.py new file mode 100644 index 00000000..41dbc9b8 --- /dev/null +++ b/rest/initscript.py @@ -0,0 +1,58 @@ +from django.http import HttpResponse +import json +from manifold.core.query import Query +from manifoldapi.manifoldapi import execute_admin_query + +def dispatch(request, action): + + results = [] + error = None + try: + if request.method == 'POST': + req_items = request.POST + elif request.method == 'GET': + req_items = request.GET + + for el in req_items.items(): + if el[0].startswith('slice_hrn'): + slice_hrn = el[1] + elif el[0].startswith('initscript_code'): + initscript_code = el[1] + + if (action == 'get') : + # select initscript_code from initscript where slice_hrn=='onelab.upmc.express' + query = Query.get('initscript').filter_by('slice_hrn', '==', slice_hrn).select('initscript_code') + results = execute_admin_query(request, query) + + if (action == 'update') : + # UPDATE initscript SET initscript_code='test3' where slice_hrn=='onelab.upmc.express' + params = {'initscript_code' : initscript_code} + query = Query.update('initscript').filter_by('slice_hrn', '==', slice_hrn).set(params) + results = execute_admin_query(request, query) + + if results[0]['initscript_code']==1: + results[0]['initscript_code']=initscript_code + else: + error = "Error in update return value" + + if (action == 'delete') : + # delete from initscript where slice_hrn=='onelab.upmc.express' + query = Query.delete('initscript').filter_by('slice_hrn', '==', slice_hrn) + results = execute_admin_query(request, query) + + if results[0]['initscript_code']==1: + results[0]['initscript_code']="" + else: + error = "Error in delete return value" + except Exception, e: + error = str(e) + #print "Exception : ",e + if error is not None: + ret = { "ret" : 1, "error" : error } + elif not results : + ret = { "ret" : 1, "slice_hrn" : slice_hrn } + else : + ret = { "ret" : 0, "slice_hrn" : slice_hrn } + ret.update(results[0]) + + return HttpResponse(json.dumps(ret), content_type="application/json") -- 2.43.0