CLoudLab integration
authorLoic Baron <loic.baron@lip6.fr>
Tue, 7 Feb 2017 06:18:23 +0000 (07:18 +0100)
committerLoic Baron <loic.baron@lip6.fr>
Tue, 7 Feb 2017 06:18:23 +0000 (07:18 +0100)
myslice/urls.py
portal/cloudlabview.py [new file with mode: 0644]
portal/templates/cloudlab.html [new file with mode: 0644]

index 8f10828..59397e5 100644 (file)
@@ -37,6 +37,7 @@ import portal.platformsview
 import portal.dashboardview
 import portal.homeview
 import portal.newsview
+import portal.cloudlabview
 import portal.loginwidget
 
 platforms_view=portal.platformsview.PlatformsView.as_view()
@@ -109,6 +110,7 @@ urls = [
     #
     # Portal
     (r'^news/?$', portal.newsview.NewsView.as_view()),
+    (r'^cloudlab/?$', portal.cloudlabview.CloudView.as_view()),
     (r'^resources/(?P<slicename>[^/]+)/?$', portal.sliceresourceview.SliceResourceView.as_view()),
     (r'^users/(?P<slicename>[^/]+)/?$', portal.slicetabusers.SliceUserView.as_view()),
     (r'^my_url/?$', portal.omn.OMNView.as_view()),
diff --git a/portal/cloudlabview.py b/portal/cloudlabview.py
new file mode 100644 (file)
index 0000000..aabc396
--- /dev/null
@@ -0,0 +1,53 @@
+import json
+from django.core.context_processors import csrf
+from django.http import HttpResponseRedirect
+from django.contrib.auth import authenticate, login, logout
+from django.template import RequestContext
+from django.shortcuts import render_to_response
+from django.shortcuts import render
+
+from unfold.loginrequired import LoginRequiredAutoLogoutView
+from manifold.core.query     import Query
+from manifoldapi.manifoldapi import execute_query
+
+from manifoldapi.manifoldresult import ManifoldResult
+from myslice.configengine import ConfigEngine
+
+from myslice.theme import ThemeView
+from myslice.settings                   import logger
+
+class CloudView (LoginRequiredAutoLogoutView, ThemeView):
+    template_name = 'cloudlab.html'
+
+    def get (self, request, state=None):
+        env = {}
+        pkey = None
+        cert = None
+        account_query  = Query().get('local:account').select('user_id','platform_id','auth_type','config')
+        account_details = execute_query(self.request, account_query)
+        # Get the accounts of the current logged in user
+        for account_detail in account_details:
+            try:
+                account_config = json.loads(account_detail['config'])
+                if 'user_private_key' in account_config:
+                    pkey = account_config['user_private_key']
+                if 'gid' in account_config:
+                    cert = account_config['gid']
+            except ValueError as e:
+                print('not a JSON')
+
+        env['supername'] = 'Amira'
+        env['cert'] = cert
+        env['key'] = pkey                                                      
+        if request.user.is_authenticated(): 
+            env['person'] = self.request.user
+            env['username'] = self.request.user
+        else: 
+            env['person'] = None
+            env['username'] = None
+    
+        env['theme'] = self.theme
+        env['section'] = ""
+
+        return render_to_response(self.template_name, env, context_instance=RequestContext(request))
+
diff --git a/portal/templates/cloudlab.html b/portal/templates/cloudlab.html
new file mode 100644 (file)
index 0000000..4133cb9
--- /dev/null
@@ -0,0 +1,33 @@
+{% extends "layout_wide.html" %}
+{% block content %}
+<h1>Your name is : {{username}}</h1>
+
+<script src="/static/geni-auth.js"></script>
+<script type="text/plain" id="certificate">
+{{key}}
+{{cert}}
+</script>
+<script>
+  function sendCertificate()
+  {
+    var script = document.getElementById('certificate');
+    genilib.sendCertificate(script.innerHTML);
+  }
+</script>
+
+<center>
+  <h2><br>
+  A tool has requested your private certificate.
+  </h2>
+  <p>If you accept, the tool will be able to act on your behalf. Click confirm below if you wish to proceed or close this window to cancel.
+  </p>
+
+  <form onsubmit="sendCertificate(); return false;" >
+    <b><input type=submit name=confirmed value=Confirm></b>
+<!--    <b><input type=submit name=canceled value=Cancel></b> -->
+  </form>
+
+
+
+{% endblock %}
+