Merge branch 'onelab' of ssh://git.onelab.eu/git/myslice into onelab
authorCostas Yiotis <coyiotis@gmail.com>
Mon, 24 Nov 2014 10:36:01 +0000 (12:36 +0200)
committerCostas Yiotis <coyiotis@gmail.com>
Mon, 24 Nov 2014 10:36:01 +0000 (12:36 +0200)
portal/account.py [new file with mode: 0644]
portal/accountview.py
portal/homeview.py
portal/platform.py [new file with mode: 0644]
portal/templates/onelab/onelab_account-view.html
portal/templates/onelab/onelab_home-view.html

diff --git a/portal/account.py b/portal/account.py
new file mode 100644 (file)
index 0000000..7d08e1c
--- /dev/null
@@ -0,0 +1,45 @@
+from manifold.core.query                import Query
+from manifoldapi.manifoldapi            import execute_query
+
+from datetime import datetime
+import time
+import dateutil.parser
+import calendar
+
+import json, os, re, itertools
+
+class Account:
+    def __init__ (self, platform_id, user_id):
+        account_query  = Query().get('local:account').select('user_id','platform_id','auth_type','config').filter_by('platform_id', '==', platform_id).filter_by('user_id', '==', user_id)
+        account_details = execute_query(self.request, account_query)
+        self.user_id     = account_details['user_id']
+        self.platform_id = account_details['platform_id']
+        self.auth_type   = account_details['auth_type']
+        self.config      = account_details['config']
+        account_config = json.loads(account_details['config'])
+
+        self.usr_hrn = account_config.get('user_hrn',None)
+        self.pub_key = account_config.get('user_public_key',None)
+        self.reference = account_config.get ('reference_platform',None)
+
+        self.user_cred = account_config.get('delegated_user_credential',None)
+        self.user_cred_expiration = get_expiration(self.user_cred)
+        
+        slice_creds = account_config.get('delegated_slice_credentials',None)
+        for slice_name, slice_cred in slice_creds.iteritems():
+            self.slice_cred_expiration = get_expiration(self.slice_cred)
+
+        self.auth_cred = account_config.get('delegated_authority_credentials',None)
+        self.auth_cred_expiration = get_expiration(self.auth_cred)
+
+def get_expiration (credential, format = 'UTC'):
+    exp_date = re.search('<expires>(.*)</expires>', credential)
+    if exp_date:
+        exp_date = exp_date.group(1)
+        if format == 'timestamp':
+            exp_date = calendar.timegm(dateutil.parser.parse(exp_date).utctimetuple())
+    else:
+        exp_date = None
+    return exp_date
+
index 5048383..325796b 100644 (file)
@@ -16,8 +16,9 @@ from django.contrib.auth.decorators     import login_required
 
 from myslice.theme import ThemeView
 
+from portal.account                     import Account, get_expiration
 #
-import json, os, re, itertools
+import json, os, re, itertools, time
 from OpenSSL import crypto
 from Crypto.PublicKey import RSA
 
@@ -210,7 +211,11 @@ class AccountView(LoginRequiredAutoLogoutView, ThemeView):
         if acc_user_cred == {} or acc_user_cred == 'N/A':
             user_cred = 'no_creds'
         else:
-            user_cred = 'has_creds'
+            exp_date = get_expiration(acc_user_cred, 'timestamp')
+            if exp_date < time.time():
+                user_cred = 'creds_expired'
+            else:
+                user_cred = 'has_creds'
 
         context = super(AccountView, self).get_context_data(**kwargs)
         context['principal_acc'] = principal_acc_list
index f1ac37c..3e9514f 100644 (file)
@@ -17,9 +17,10 @@ from ui.topmenu                         import topmenu_items, the_user
 from myslice.configengine               import ConfigEngine
 
 from myslice.theme                      import ThemeView
+from portal.account                     import Account, get_expiration
 from portal.models                      import PendingSlice
 
-import json
+import json, time
 import activity.user
 
 class HomeView (FreeAccessView, ThemeView):
@@ -97,8 +98,12 @@ class HomeView (FreeAccessView, ThemeView):
                     if acc_user_cred == {} or acc_user_cred == 'N/A':
                         user_cred = 'no_creds'
                     else:
-                        user_cred = 'has_creds'
-                    
+                        exp_date = get_expiration(acc_user_cred, 'timestamp')
+                        if exp_date < time.time():
+                            user_cred = 'creds_expired'
+                        else:
+                            user_cred = 'has_creds'
+
                     # list the pending slices of this user
                     pending_slices = []
                     for slices in PendingSlice.objects.filter(type_of_nodes__iexact=self.request.user).all():
@@ -160,7 +165,11 @@ class HomeView (FreeAccessView, ThemeView):
             if acc_user_cred == {} or acc_user_cred == 'N/A':
                 user_cred = 'no_creds'
             else:
-                user_cred = 'has_creds'
+                exp_date = get_expiration(acc_user_cred, 'timestamp')
+                if exp_date < time.time():
+                    user_cred = 'creds_expired'
+                else:
+                    user_cred = 'has_creds'
 
             # list the pending slices of this user
             pending_slices = []
diff --git a/portal/platform.py b/portal/platform.py
new file mode 100644 (file)
index 0000000..f224056
--- /dev/null
@@ -0,0 +1,21 @@
+from manifold.core.query                import Query
+from manifoldapi.manifoldapi            import execute_query
+
+class Platform:
+    def __init__ (self, id = None, name = None):
+        if id is not None:
+            platform_query  = Query().get('local:platform').select('platform_id','platform','gateway_type','disabled').filter_by('platform_id', '==', platform_id)
+        if name is not None:
+            platform_query  = Query().get('local:platform').select('platform_id','platform','gateway_type','disabled').filter_by('platform', '==', platform)
+        self.id       = platform_query['platform_id']
+        self.name     = platform_query['platform']
+        self.type     = platform_query['gateway_type']
+        self.disabled = platform_query['disabled']
+
+#class Platforms:
+#    def __init__ (self):
+#        platforms_query  = Query().get('local:platform').select('platform_id','platform','gateway_type','disabled')
+#        platforms_details = execute_query(self.request, platform_query)
+#        for platform_detail in platforms_details:
+#            Platform(id = platform_detail['platform_id'])
index 549ec6b..7ac9578 100644 (file)
@@ -9,7 +9,10 @@
        </div>
         {%if 'no_creds'  in user_cred %}
     <p class="command"><a href="#" style="color:red" data-toggle="modal" data-target="#myModal">NO CREDENTIALS</a> are delegated to the portal!</p>
-{%endif%}
+    {%endif%}
+        {%if 'creds_expired'  in user_cred %}
+    <p class="command"><a href="#" style="color:red" data-toggle="modal" data-target="#myModal">EXPIRED CREDENTIALS</a> Please delegate again your credentials to the portal!</p>
+    {%endif%}
 
 </div>
 {% if messages %}
index 944bcbe..9170b4a 100644 (file)
@@ -51,6 +51,9 @@
           {%if 'no_creds'  in user_cred %}
       <p class="command"><a href="#" style="color:red" data-toggle="modal" data-target="#myModal">NO CREDENTIALS</a> are delegated to the portal!</p>
   {%endif%}
+        {%if 'creds_expired'  in user_cred %}
+    <p class="command"><a href="#" style="color:red" data-toggle="modal" data-target="#myModal">EXPIRED CREDENTIALS</a> Please delegate again your credentials to the portal!</p>
+    {%endif%}
 
        <div class="row">
                {%if 'is_pi'  in pi %}
                $('button#slicerequestbtn').click(function() {
                        window.location="/portal/slice_request/";
                });
-/*-------
-List of slices has been moved in 
-portal/templates/base.html
-This should go into session
---------*/
+
+        /*
+            Launch queries to get the resources and leases in Manifold Cache
+        */
+            
+        $.post("/rest/resource/", function( data ) {
+        });
+        $.post("/rest/lease/", function( data ) {
+        });
+        
+        /*-------
+        List of slices has been moved in 
+        portal/templates/base.html
+        This is now in localStorage 
+        --------*/
+        // myslice.user is in LocalStorage
+        if(myslice.user.slices.length>0){
+            $.each( myslice.user.slices, function(i, val) {
+                /*
+                Launch a Query for each slice to get resources and leases in Manifold Cache
+                */
+                $.post("/rest/slice/", { 'filters': { 'slice_hrn' : val } }, function(data) {
+                });
+            });
+        }
 });
 </script>
 {# widget "_widget-monitor.html" #}