2 # implements support for SFA records stored in db tables
4 # TODO: Use existing PLC database methods? or keep this separate?
7 from sfa.trust.gid import *
8 from sfa.util.record import *
9 from sfa.util.config import *
10 from sfa.util.filter import *
11 from sfa.trust.hierarchy import *
12 from sfa.trust.certificate import *
13 from sfa.trust.auth import *
14 from sfa.senslab.OARrestapi import *
15 from sfa.senslab.LDAPapi import *
19 def __init__(self, record_filter = None):
22 self.senslabauth=Hierarchy()
24 self.authname=config.SFA_REGISTRY_ROOT_AUTH
25 authinfo=self.senslabauth.get_auth_info(self.authname)
28 gid=authinfo.get_gid_object()
33 def db_fields(self, obj=None):
37 def is_writable (key,value,dict):
38 # if not mentioned, assume it's writable (e.g. deleted ...)
39 if key not in dict: return True
40 # if mentioned but not linked to a Parameter object, idem
41 if not isinstance(dict[key], Parameter): return True
42 # if not marked ro, it's writable
43 if not dict[key].ro: return True
51 def remove(self, record):
54 def insert(self, record):
57 def update(self, record):
60 def quote_string(self, value):
61 return str(self.db.quote(value))
63 def quote(self, value):
64 return self.db.quote(value)
67 def oarFind(self, record_filter = None, columns=None):
71 if 'authority' in record_filter:
73 if record_filter['authority']== self.authname :
75 print>> sys.stderr , "ET MERDE !!!!"
78 # which is NOT senslab
81 if not 'hrn' in record_filter:
82 print >>sys.stderr,"find : don't know how to handle filter ",record_filter
86 h=record_filter['hrn']
87 if isinstance(h,list):
93 head,sep,tail=hrn.partition(".")
94 if head != self.authname :
95 print >>sys.stderr,"i know nothing about",hrn, " my authname is ", self.authname, " not ", splited_hrn[0]
99 node_list = self.oar.GetNodes( node_ids)
101 for node in node_list:
102 hrn=self.authname+"."+node['hostname']
105 # 'email': ldapentry[1]['mail'][0],
106 # 'first_name': ldapentry[1]['givenName'][0],
107 # 'last_name': ldapentry[1]['sn'][0],
109 # 'gid': gid.save_to_string(),
111 'authority': self.authname,
112 'peer_authority': '',
115 'date_created' : 'none',
116 'last_updated': 'none'
121 def find(self, record_filter = None, columns=None):
122 # senslab stores its users in an ldap dictionnary
123 # and nodes in a oar scheduller database
124 # both should be interrogated.
125 print >>sys.stderr,"find : ",record_filter
126 if not isinstance(record_filter,dict):
127 print >>sys.stderr,"find : record_filter is not a dict"
128 print >>sys.stderr,record_filter.__class__
131 if 'type' in record_filter:
132 if record_filter['type'] == 'slice':
133 print >>sys.stderr,"find : don't know how to handle slices yet"
135 if record_filter['type'] == 'authority':
136 if 'hrn' in record_filter and record_filter['hrn']==self.authname:
139 print >>sys.stderr,"find which authority ?"
141 if record_filter['type'] == 'user':
142 return self.ldap.ldapFind(record_filter, columns)
143 if record_filter['type'] == 'node':
144 return self.ldap.ldapFind(record_filter, columns)
146 print >>sys.stderr,"unknown type to find : ", record_filter['type']
149 allResults = self.ldap.ldapFind(record_filter, columns)
150 allResults+= self.oarFind(record_filter, columns)
154 def findObjects(self, record_filter = None, columns=None):
156 print >>sys.stderr,"find : ",record_filter
157 # print record_filter['type']
158 # if record_filter['type'] in ['authority']:
159 # print "findObjectAuthority"
160 results = self.find(record_filter, columns)
162 for result in results:
163 if result['type'] in ['authority']:
164 result_rec_list.append(AuthorityRecord(dict=result))
165 elif result['type'] in ['node']:
166 result_rec_list.append(NodeRecord(dict=result))
167 elif result['type'] in ['slice']:
168 result_rec_list.append(SliceRecord(dict=result))
169 elif result['type'] in ['user']:
170 result_rec_list.append(UserRecord(dict=result))
172 result_rec_list.append(SfaRecord(dict=result))
174 return result_rec_list
180 def sfa_records_purge(self):