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
20 from sfa.planetlab.plxrn import hash_loginbase
24 class ExperimentView (FreeAccessView, ThemeView):
25 template_name = 'slice-tab-experiment.html'
27 def get (self, request, slicename, state=None):
29 username = self.request.user
31 split_slicename = slicename.split('.')
32 ple_slicename = hash_loginbase(split_slicename[0] + '.' + split_slicename[1]) + '_' + split_slicename[2]
37 query_current_resources = Query.get('slice').select('resource').filter_by('slice_hrn','==',slicename)
38 current_resources = execute_query(request, query_current_resources)
41 nitos_resource_list=[]
42 nitos_paris_resource_list=[]
43 iotlab_resource_list=[]
45 for resources in current_resources:
46 list_res = resources['resource']
50 split_list = res.split('+') # split the resource urn
53 if [s for s in split_list if 'ple' in s]: # find ple resources
54 res_hrn = split_list[-1] # last element is resource hrn
55 ple_resource_list.append(res_hrn)
56 if [s for s in split_list if 'omf:paris.fit-nitos.fr' in s]: # find nitos_paris resources
57 res_hrn = split_list[-1] # last element is resource hrn
58 nitos_paris_resource_list.append(res_hrn)
59 if [s for s in split_list if 'iotlab' in s]: # find iotlab resources
60 res_hrn = split_list[-1] # last element is resource hrn
61 iotlab_resource_list.append(res_hrn)
62 if [s for s in split_list if 'omf:nitos.indoor' in s]: # find nitos_indoor resources
63 res_hrn = split_list[-1] # last element is resource hrn
64 nitos_resource_list.append(res_hrn)
65 if [s for s in split_list if 'omf:nitos.outdoor' in s]: # find nitos_outdoor resources
66 res_hrn = split_list[-1] # last element is resource hrn
67 nitos_resource_list.append(res_hrn)
71 print "Exception in slicetabexperiment.py in OneLab resource search %s" % e
73 #print "list of ple res hrns"
74 #print ple_resource_list
75 #print "list of nit_paris res hrns"
76 #print nitos_paris_resource_list
77 #print "list of iotLab res hrns"
78 #print iotlab_resource_list
79 #print "list of nitos res hrns"
80 #print nitos_resource_list
84 engine = ConfigEngine()
85 userData = "Basic " + (engine.iotlab_admin_user() + ":" + engine.iotlab_admin_password()).encode("base64").rstrip()
86 req = urllib2.Request(engine.iotlab_url())
87 req.add_header('Accept', 'application/json')
88 req.add_header("Content-type", "application/x-www-form-urlencoded")
89 req.add_header('Authorization', userData)
90 # make the request and print the results
91 res = urllib2.urlopen(req)
92 all_users = json.load(res)
93 except urllib2.URLError as e:
94 print "There is a problem in getting iotlab users %s" % e.reason
98 #getting the login from email
99 #initial value no-account == contact_admin
100 iot_login = 'contact_admin'
101 username = str(username)
102 for user in all_users:
103 if user['email'] == username:
104 iot_login = user['login']
106 return render_to_response(self.template, { 'theme' : self.theme,'slicename':slicename, 'ple_slicename':ple_slicename, 'username':username, 'ple_resources':ple_resource_list, 'nitos_resources': nitos_resource_list, 'nitos_paris_resources':nitos_paris_resource_list, 'iotlab_resources':iotlab_resource_list, 'iot_login':iot_login }, context_instance=RequestContext(request))