Merge branch 'onelab' of ssh://git.onelab.eu/git/myslice into onelab
authorYasin <mohammed-yasin.rahman@lip6.fr>
Mon, 8 Dec 2014 14:37:07 +0000 (15:37 +0100)
committerYasin <mohammed-yasin.rahman@lip6.fr>
Mon, 8 Dec 2014 14:37:07 +0000 (15:37 +0100)
README
manifoldapi/static/js/manifold.js
myslice/urls.py
rest/monitor.py
rest/sfa_api.py [new file with mode: 0644]

diff --git a/README b/README
index b1f201d..3530ed2 100644 (file)
--- a/README
+++ b/README
@@ -1,6 +1,6 @@
 This file documents the contents of this module
 change
-Last update 4 sept. 2013
+Last update 4 DEC. 2014
 
 See the devel/ subdir for more devel-oriented doc.
 
index ca111de..fe493cd 100644 (file)
@@ -243,6 +243,7 @@ function QueryStore() {
         // XXX query.change_action() should become deprecated
         update_query = query.clone();
         update_query.action = 'update';
+        update_query.fields = [];
         update_query.analyzed_query.action = 'update';
         update_query.params = {};
         update_query_ext = new QueryExt(update_query);
@@ -1363,8 +1364,9 @@ case TYPE_LIST_OF_VALUES:
                 case TYPE_LIST_OF_VALUES: // XXX Until fixed
                 case TYPE_LIST_OF_RECORDS:
                     var key, new_state, cur_query_uuid;
-
-                    cur_query_uuid = query.analyzed_query.subqueries[field].query_uuid;
+                    if($.inArray(field,Object.keys(query.analyzed_query.subqueries)) > -1){
+                        cur_query_uuid = query.analyzed_query.subqueries[field].query_uuid;
+                    }
 
                     // example: slice.resource
                     //  - update_query_orig.params.resource = resources in slice before update
@@ -1449,6 +1451,8 @@ case TYPE_LIST_OF_VALUES:
         var query_ext = manifold.query_store.find_query_ext(query.query_uuid);
         query_ext.query_state = QUERY_STATE_DONE;
 
+        var tmp_query = manifold.query_store.find_analyzed_query(query.query_uuid);
+        manifold.publish_result_rec(tmp_query, records);
 
         // Send DONE message to plugins
         query.iter_subqueries(function(sq, data, parent_query) {
@@ -1884,6 +1888,7 @@ case TYPE_LIST_OF_VALUES:
                 break;
 
             case RUN_UPDATE:
+                query_ext.main_query_ext.update_query_ext.query.fields = [];
                 manifold.run_query(query_ext.main_query_ext.update_query_ext.query);
                 break;
 
index 91511b7..af9a800 100644 (file)
@@ -82,6 +82,7 @@ urls = [
     #
     # RESTful interface
     (r'^rest/(?P<object_type>[^/]+)/(?P<object_name>[^/]+)?/?$', 'rest.get.dispatch'),
+    (r'^sfa/(?P<method>[^/]+)/?$', 'rest.sfa_api.dispatch'),
     (r'^table/(?P<object_type>[^/]+)/(?P<object_name>[^/]+)?/?$', 'rest.get.dispatch'),
     (r'^datatable/(?P<object_type>[^/]+)/(?P<object_name>[^/]+)?/?$', 'rest.get.dispatch'),
     (r'^update/(?P<object_type>[^/]+)/(?P<object_name>[^/]+)?/?$', 'rest.update.dispatch'),
index 2252189..4372a35 100644 (file)
@@ -59,4 +59,4 @@ def servicesStatus(request):
                 result[s]['status'] = 'ko'
 
         
-    return HttpResponse(json.dumps(result), content_type="application/json")
\ No newline at end of file
+    return HttpResponse(json.dumps(result), content_type="application/json")
diff --git a/rest/sfa_api.py b/rest/sfa_api.py
new file mode 100644 (file)
index 0000000..04b156b
--- /dev/null
@@ -0,0 +1,142 @@
+from sfa.trust.certificate      import Keypair, Certificate
+from sfa.client.sfaserverproxy  import SfaServerProxy
+from sfa.client.return_value    import ReturnValue
+from sfa.util.xrn               import Xrn, get_leaf, get_authority, hrn_to_urn, urn_to_hrn
+from manifold.core.query        import Query
+from manifold.models            import db
+from manifold.models.platform   import Platform
+from manifold.models.user       import User
+
+from django.shortcuts           import render_to_response
+
+from unfold.loginrequired       import LoginRequiredView
+
+from rest import ObjectRequest, error
+
+from string import join
+
+from django.http import HttpResponse
+from rest import error
+import os,json
+
+import ConfigParser 
+
+def dispatch(request, method):
+    Config = ConfigParser.ConfigParser()
+    Config.read(os.getcwd() + "/myslice/monitor.ini")
+
+    # hardcoded user to be replaced by auth
+    user_email = "loic.baron@lip6.fr"
+
+    # Get this as parameters
+    slice_hrn = "fed4fire.upmc.berlin"
+    urn = hrn_to_urn(slice_hrn, "slice")
+    #urn = hrn_to_urn("fed4fire.upmc.loic_baron", "user")
+
+    platforms = list()
+    options   = list()
+    rspec = ''
+    results = dict()
+
+    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('rspec'):
+            rspec += el[1]
+        if el[0].startswith('platform'):
+            platforms += req_items.getlist('platform[]')
+        elif el[0].startswith('options'):
+            options += req_items.getlist('options[]')
+
+    if len(platforms)==0:
+        platforms.append('myslice')
+    #results = {'method':method,'platforms':platforms,'rspec':rspec,'options':options}
+
+    from manifoldapi.manifoldapi    import execute_admin_query
+    for pf in platforms:
+        platform = get_platform_config(pf)
+        print platform
+        if 'sm' in platform and len(platform['sm']) > 0:
+            print 'sm'
+            server_url = platform['sm']
+        if 'rm' in platform and len(platform['rm']) > 0:
+            print 'rm'
+            server_url = platform['rm']
+        if 'registry' in platform and len(platform['registry']) > 0:
+            print 'registry'
+            server_url = platform['registry']
+    
+        if not Config.has_option('monitor', 'cert') :
+             return HttpResponse(json.dumps({'error' : '-1'}), content_type="application/json")
+
+        cert = os.path.abspath(Config.get('monitor', 'cert'))
+        if not os.path.isfile(cert) :
+             return HttpResponse(json.dumps({'error' : '-1'}), content_type="application/json")
+
+        if not Config.has_option('monitor', 'pkey') :
+             return HttpResponse(json.dumps({'error' : '-2'}), content_type="application/json")
+
+        pkey = os.path.abspath(Config.get('monitor', 'pkey'))
+        if not os.path.isfile(pkey) :
+             return HttpResponse(json.dumps({'error' : '-2'}), content_type="application/json")
+        server = SfaServerProxy(server_url, pkey, cert)
+
+        # Get user config from Manifold
+        user_config = get_user_config(user_email, pf)
+        if 'delegated_user_credential' in user_config:
+            user_cred = user_config['delegated_user_credential']
+        else:
+            user_cred = {}
+
+        #if 'delegated_slice_credentials' in user_config:
+        #    for slice_name, cred in user_config['delegated_slice_credentials']:
+        #        if slice_name == slice_param
+
+        if method == "GetVersion": 
+            result = server.GetVersion()
+        elif method == "ListResources":
+            api_options = {}
+            #api_options ['call_id'] = unique_call_id()
+            api_options['geni_rspec_version'] = {'type': 'GENI', 'version': '3'}
+            result = server.ListResources([user_cred], api_options)
+        elif method == "Describe":
+            api_options = {}
+            #api_options ['call_id'] = unique_call_id()
+            api_options['geni_rspec_version'] = {'type': 'GENI', 'version': '3'}
+            result = server.Describe([urn] ,[object_cred], api_options)
+
+        else:
+            return HttpResponse(json.dumps({'error' : '-3','msg':'method not supported yet'}), content_type="application/json")
+
+        results[pf] = result
+
+    return HttpResponse(json.dumps(results), content_type="application/json")
+
+def get_user_account(user_email, platform_name):
+    """
+    Returns the user configuration for a given platform.
+    This function does not resolve references.
+    """
+    user = db.query(User).filter(User.email == user_email).one()
+    platform = db.query(Platform).filter(Platform.platform == platform_name).one()
+    accounts = [a for a in user.accounts if a.platform == platform]
+    if not accounts:
+        raise Exception, "this account does not exist"
+
+    if accounts[0].auth_type == 'reference':
+        pf = json.loads(accounts[0].config)['reference_platform']
+        return get_user_account(user_email, pf)
+
+    return accounts[0]
+
+def get_user_config(user_email, platform_name):
+    account = get_user_account(user_email, platform_name)
+    return json.loads(account.config) if account.config else {}
+
+def get_platform_config(platform_name):
+    platform = db.query(Platform).filter(Platform.platform == platform_name).one()
+    return json.loads(platform.config) if platform.config else {}