First modifications for upcoming migration to OAR2.5 and senslab prod LDAP.
[sfa.git] / sfa / senslab / slabdriver.py
index dcd3d9b..c2f7f4c 100644 (file)
@@ -14,8 +14,8 @@ from sfa.storage.alchemy import dbsession
 from sfa.storage.model import RegRecord
 
 
-from sfa.trust.certificate import *
-from sfa.trust.credential import *
+#from sfa.trust.certificate import *
+from sfa.trust.credential import Credential
 from sfa.trust.gid import GID
 
 from sfa.managers.driver import Driver
@@ -29,7 +29,7 @@ from sfa.util.plxrn import slicename_to_hrn, hostname_to_hrn, hrn_to_pl_slicenam
 # is taken care of 
 # SlabDriver should be really only about talking to the senslab testbed
 
-## thierry : please avoid wildcard imports :)
+
 from sfa.senslab.OARrestapi import  OARrestapi
 from sfa.senslab.LDAPapi import LDAPapi
 
@@ -426,25 +426,38 @@ class SlabDriver(Driver):
         return return_records
         
      
-            
+    #TODO  : Handling OR request in make_ldap_filters_from_records instead of the for loop 
+    #over the records' list
     def GetPersons(self, person_filter=None, return_fields=None):
-        
-        #if isinstance(person_filter,list):
-            #for f in person_filter:
-                #person = self.ldap.ldapSearch(f)
-        #if isinstance(person_filter,dict):    
-        person_list = self.ldap.ldapFindHrn({'authority': self.root_auth })
-        
-        #check = False
-        #if person_filter and isinstance(person_filter, dict):
-            #for k in  person_filter.keys():
-                #if k in person_list[0].keys():
-                    #check = True
+        """
+        person_filter should be a list of dictionnaries when not set to None.
+        Returns a list of users found.
+       
+        """
+        print>>sys.stderr, "\r\n \r\n \t\t\t GetPersons person_filter %s" %(person_filter)
+        person_list = []
+        if person_filter and isinstance(person_filter,list):
+        #If we are looking for a list of users (list of dict records)
+        #Usually the list contains only one user record
+            for f in person_filter:
+                person = self.ldap.ldapFindHrn(f)
+                person_list.append(person)
+          
+        else:
+              person_list  = self.ldap.ldapFindHrn()  
                     
-        return_person_list = parse_filter(person_list,person_filter ,'persons', return_fields)
-        if return_person_list:
-            print>>sys.stderr, " \r\n GetPersons person_filter %s return_fields %s  " %(person_filter,return_fields)
-            return return_person_list
+        return person_list
+            #person_list = self.ldap.ldapFindHrn({'authority': self.root_auth })
+        ##check = False
+        ##if person_filter and isinstance(person_filter, dict):
+            ##for k in  person_filter.keys():
+                ##if k in person_list[0].keys():
+                    ##check = True
+                    
+        #return_person_list = parse_filter(person_list,person_filter ,'persons', return_fields)
+        #if return_person_list:
+            #print>>sys.stderr, " \r\n GetPersons person_filter %s return_fields %s  " %(person_filter,return_fields)
+            #return return_person_list
 
     def GetTimezone(self):
         server_timestamp,server_tz = self.oar.parser.SendRequest("GET_timezone")
@@ -510,7 +523,7 @@ class SlabDriver(Driver):
             
     def GetReservedNodes(self):
         # this function returns a list of all the nodes already involved in an oar job
-
+       #jobs=self.oar.parser.SendRequest("GET_reserved_nodes") 
        jobs=self.oar.parser.SendRequest("GET_jobs_details") 
        nodes=[]
        for j in jobs :
@@ -905,7 +918,8 @@ class SlabDriver(Driver):
                     'person_ids':[rec['record_id_user']]})
                     #retourne une liste 100512
                     
-                    user_slab = self.GetPersons({'hrn':recuser.hrn})
+                    #GetPersons takes [] as filters 
+                    user_slab = self.GetPersons([{'hrn':recuser.hrn}])
                     
 
                     rec.update({'type':'slice','hrn':rec['slice_hrn']})