1 # this somehow is not used anymore - should it not be ?
2 from django.core.context_processors import csrf
3 from django.http import HttpResponseRedirect
4 from django.contrib.auth import authenticate, login, logout
5 from django.template import RequestContext
6 from django.shortcuts import render_to_response
7 from django.shortcuts import render
9 from unfold.loginrequired import FreeAccessView
11 from manifold.core.query import Query
12 from manifoldapi.manifoldapi import execute_query
13 from manifoldapi.manifoldresult import ManifoldResult
14 from ui.topmenu import topmenu_items, the_user
15 from myslice.configengine import ConfigEngine
17 from myslice.theme import ThemeView
18 from myslice.configengine import ConfigEngine
19 from myslice.settings import logger
21 from sfa.planetlab.plxrn import hash_loginbase
25 class ExperimentView (FreeAccessView, ThemeView):
26 # parent View is portal/sliceview.py
28 template_name = 'slice-tab-experiment.html'
30 def get (self, request, slicename, state=None):
32 username = self.request.user
34 pf_query = Query().get('local:platform').filter_by('disabled', '==', '0').filter_by('gateway_type', '==', 'sfa').select('platform')
35 res_platforms = execute_query(request, pf_query)
36 platforms = [p['platform'] for p in res_platforms]
37 len_platforms = len(platforms)
38 #query_current_resources = Query.get('slice').select('resource','parent_authority').filter_by('slice_hrn','==',slicename)
39 #current_resources = execute_query(request, query_current_resources)
41 #parent_authority = current_resources[0]['parent_authority']
43 #split_slicename = slicename.split('.')
44 #ple_slicename = hash_loginbase(parent_authority) + '_' + split_slicename[-1]
47 #nitos_resource_list=[]
48 #nitos_paris_resource_list=[]
49 #iotlab_resource_list=[]
51 # for resources in current_resources:
52 # list_res = resources['resource']
53 # for res in list_res:
54 # split_list = res.split('+') # split the resource urn
55 # if [s for s in split_list if 'ple' in s]: # find ple resources
56 # res_hrn = split_list[-1] # last element is resource hrn
57 # ple_resource_list.append(res_hrn)
58 # if [s for s in split_list if 'omf:paris.fit-nitos.fr' in s]: # find nitos_paris resources
59 # res_hrn = split_list[-1] # last element is resource hrn
60 # nitos_paris_resource_list.append(res_hrn)
61 # if [s for s in split_list if 'iotlab' in s]: # find iotlab resources
62 # res_hrn = split_list[-1] # last element is resource hrn
63 # iotlab_resource_list.append(res_hrn)
64 # if [s for s in split_list if 'omf:nitos.indoor' in s]: # find nitos_indoor resources
65 # res_hrn = split_list[-1] # last element is resource hrn
66 # nitos_resource_list.append(res_hrn)
67 # if [s for s in split_list if 'omf:nitos.outdoor' in s]: # find nitos_outdoor resources
68 # res_hrn = split_list[-1] # last element is resource hrn
69 # nitos_resource_list.append(res_hrn)
72 #except Exception as e:
73 # logger.error("Exception in slicetabexperiment.py in OneLab resource search {}".format(e))
75 ##logger.debug("list of ple res hrns")
76 ##logger.debug(ple_resource_list)
77 ##logger.debug("list of nit_paris res hrns")
78 ##logger.debug(nitos_paris_resource_list)
79 ##logger.debug("list of iotLab res hrns")
80 ##logger.debug(iotlab_resource_list)
81 ##logger.debug("list of nitos res hrns")
82 ##logger.debug(nitos_resource_list)
85 ##get all iotlab users
88 # engine = ConfigEngine()
89 # userData = "Basic " + (engine.iotlab_admin_user() + ":" + engine.iotlab_admin_password()).encode("base64").rstrip()
90 # req = urllib2.Request(engine.iotlab_url())
91 # req.add_header('Accept', 'application/json')
92 # req.add_header("Content-type", "application/x-www-form-urlencoded")
93 # req.add_header('Authorization', userData)
94 # # make the request and print the results
95 # res = urllib2.urlopen(req)
96 # all_users = json.load(res)
97 #except urllib2.URLError as e:
98 # logger.error("There is a problem in getting iotlab users {}".format(e.reason))
101 ##getting the login from email
102 ##initial value no-account == contact_admin
103 #iot_login = 'contact_admin'
104 #username = str(username)
105 #for user in all_users:
106 # if user['email'] == username:
107 # iot_login = user['login']
108 env = { 'theme' : self.theme,
109 'slicename':slicename,
110 'platforms':platforms,
111 'len_platforms': len_platforms,
112 #'ple_slicename':ple_slicename,
113 #'username':username,
114 #'ple_resources':ple_resource_list,
115 #'nitos_resources': nitos_resource_list,
116 #'nitos_paris_resources':nitos_paris_resource_list,
117 #'iotlab_resources':iotlab_resource_list,
118 #'iot_login':iot_login,
119 'request':self.request,
121 return render_to_response(self.template, env, context_instance=RequestContext(request))