X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=portal%2Fslicetabexperiment.py;h=138754a0da30c993b96f6d84579d49020425735c;hb=6df317a72253c8f590630a331a4576784959d3e9;hp=254b6765492b18183c3ff4d376cf026300c56c05;hpb=7464fb5c0d4d4857963b52b944b27df41e4ec1f6;p=myslice.git diff --git a/portal/slicetabexperiment.py b/portal/slicetabexperiment.py index 254b6765..138754a0 100644 --- a/portal/slicetabexperiment.py +++ b/portal/slicetabexperiment.py @@ -16,6 +16,9 @@ from myslice.configengine import ConfigEngine from myslice.theme import ThemeView from myslice.configengine import ConfigEngine +from myslice.settings import logger + +from sfa.planetlab.plxrn import hash_loginbase import urllib2,json @@ -26,12 +29,14 @@ class ExperimentView (FreeAccessView, ThemeView): username = self.request.user - split_slicename = slicename.split('.') - ple_slicename = split_slicename[0] + '8' + split_slicename[1] + '_' + split_slicename[2] - - query_current_resources = Query.get('slice').select('resource').filter_by('slice_hrn','==',slicename) + query_current_resources = Query.get('slice').select('resource','parent_authority').filter_by('slice_hrn','==',slicename) current_resources = execute_query(request, query_current_resources) + parent_authority = current_resources[0]['parent_authority'] + + split_slicename = slicename.split('.') + ple_slicename = hash_loginbase(parent_authority) + '_' + split_slicename[-1] + ple_resource_list=[] nitos_resource_list=[] nitos_paris_resource_list=[] @@ -39,12 +44,8 @@ class ExperimentView (FreeAccessView, ThemeView): try: for resources in current_resources: list_res = resources['resource'] - #print "list_b4" - #print list_res for res in list_res: split_list = res.split('+') # split the resource urn - #print "list_after" - #print split_list if [s for s in split_list if 'ple' in s]: # find ple resources res_hrn = split_list[-1] # last element is resource hrn ple_resource_list.append(res_hrn) @@ -62,32 +63,34 @@ class ExperimentView (FreeAccessView, ThemeView): nitos_resource_list.append(res_hrn) - except Exception,e: - print "Exception in slicetabexperiment.py in OneLab resource search %s" % e + except Exception as e: + logger.error("Exception in slicetabexperiment.py in OneLab resource search {}".format(e)) - #print "list of ple res hrns" - #print ple_resource_list - #print "list of nit_paris res hrns" - #print nitos_paris_resource_list - #print "list of iotLab res hrns" - #print iotlab_resource_list - #print "list of nitos res hrns" - #print nitos_resource_list + #logger.debug("list of ple res hrns") + #logger.debug(ple_resource_list) + #logger.debug("list of nit_paris res hrns") + #logger.debug(nitos_paris_resource_list) + #logger.debug("list of iotLab res hrns") + #logger.debug(iotlab_resource_list) + #logger.debug("list of nitos res hrns") + #logger.debug(nitos_resource_list) + all_users = list() #get all iotlab users + all_users = list() try: - userData = "Basic " + (ConfigEngine.default_iotlab_admin_user + ":" + ConfigEngine.default_iotlab_admin_password).encode("base64").rstrip() - req = urllib2.Request(ConfigEngine.default_iotlab_url) + engine = ConfigEngine() + userData = "Basic " + (engine.iotlab_admin_user() + ":" + engine.iotlab_admin_password()).encode("base64").rstrip() + req = urllib2.Request(engine.iotlab_url()) req.add_header('Accept', 'application/json') req.add_header("Content-type", "application/x-www-form-urlencoded") req.add_header('Authorization', userData) # make the request and print the results res = urllib2.urlopen(req) all_users = json.load(res) - except URLError as e: - print "There is a problem in getting iotlab users %s" % e.reason + except urllib2.URLError as e: + logger.error("There is a problem in getting iotlab users {}".format(e.reason)) - #print all_users #getting the login from email #initial value no-account == contact_admin