Merge branch 'senslab2' of ssh://flab-git.pl.sophia.inria.fr/git/sfa into senslab2
authorSandrine Avakian <sandrine.avakian@inria.fr>
Thu, 27 Oct 2011 13:39:20 +0000 (15:39 +0200)
committerSandrine Avakian <sandrine.avakian@inria.fr>
Thu, 27 Oct 2011 13:39:20 +0000 (15:39 +0200)
Conflicts:
sfa/managers/registry_manager_slab.py

sfa/managers/registry_manager_slab.py
sfa/senslab/LDAPapi.py [new file with mode: 0644]
sfa/senslab/OARrestapi.py
sfa/senslab/sfa-bare [new file with mode: 0755]
sfa/senslab/table_slab.py

index e3de48c..970dbe8 100644 (file)
@@ -5,7 +5,7 @@ import sys
 from sfa.util.faults import *
 from sfa.util.prefixTree import prefixTree
 from sfa.util.record import SfaRecord
-from sfa.util.table import SfaTable
+from sfa.senslab.table_slab import SfaTable
 from sfa.util.record import SfaRecord
 from sfa.trust.gid import GID 
 from sfa.util.xrn import Xrn, get_leaf, get_authority, hrn_to_urn, urn_to_hrn
@@ -14,12 +14,15 @@ from sfa.trust.credential import Credential
 from sfa.trust.certificate import Certificate, Keypair
 from sfa.trust.gid import create_uuid
 from sfa.util.version import version_core
+from sfa.senslab.api import *
 
+myapi=SfaAPI()
 # The GENI GetVersion call
 def GetVersion(api):
-    peers =dict ([ (peername,v._ServerProxy__host) for (peername,v) in api.registries.iteritems() 
-                   if peername != api.hrn])
-    xrn=Xrn(api.hrn)
+    
+    peers =dict ([ (peername,v._ServerProxy__host) for (peername,v) in myapi.registries.iteritems() 
+                   if peername != myapi.hrn])
+    xrn=Xrn(myapi.hrn)
     return version_core({'interface':'registry',
                          'hrn':xrn.get_hrn(),
                          'urn':xrn.get_urn(),
@@ -33,13 +36,14 @@ def get_credential(api, xrn, type, is_self=False):
         hrn, type = urn_to_hrn(xrn)
 
     # Is this a root or sub authority
-    auth_hrn = api.auth.get_authority(hrn)
-    print>> sys.stderr , " \r\n        REGISTRY get_credential auth_hrn" , auth_hrn         
-    if not auth_hrn or hrn == api.config.SFA_INTERFACE_HRN:
+    auth_hrn = myapi.auth.get_authority(hrn)
+    print>> sys.stderr , " \r\n        REGISTRY get_credential auth_hrn:" , auth_hrn,"hrn : ", hrn, " Type : ", type, "is self : " , is_self,"<<"
+    if not auth_hrn or hrn == myapi.config.SFA_INTERFACE_HRN:
         auth_hrn = hrn
     # get record info
-    auth_info = api.auth.get_auth_info(auth_hrn)
+    auth_info = myapi.auth.get_auth_info(auth_hrn)
     table = SfaTable()
+    print >> sys.stderr , " findObject ", type, hrn
     records = table.findObjects({'type': type, 'hrn': hrn})
     print>> sys.stderr , " \r\n    ++    REGISTRY get_credential hrn %s records %s " %(hrn, records)      
     if not records:
@@ -48,7 +52,7 @@ def get_credential(api, xrn, type, is_self=False):
 
     # verify_cancreate_credential requires that the member lists
     # (researchers, pis, etc) be filled in
-    api.fill_record_info(record)
+    myapi.fill_record_info(record)
     record['enabled'] = True
     print>> sys.stderr , " \r\n    ++    REGISTRY get_credential hrn %s record['enabled'] %s is_self %s" %(hrn, record['enabled'], is_self)    
     if record['type']=='user':
@@ -64,7 +68,7 @@ def get_credential(api, xrn, type, is_self=False):
        print>>sys.stderr, " \r\n REGISTRY IS SELF OK caller_hrn %s--- \r\n caller_gid %s---------" %(caller_hrn,caller_gid)
     else:
        print>> sys.stderr , " \r\n    ++  ELSE   "     
-        caller_gid = api.auth.client_cred.get_gid_caller() 
+        caller_gid = myapi.auth.client_cred.get_gid_caller() 
        print>> sys.stderr , " \r\n    ++  ELSE  caller_gid %s record %s" %(caller_gid, record) 
         caller_hrn = caller_gid.get_hrn()
        print>> sys.stderr , " \r\n    ++  ELSE  caller_hrn %s " %(caller_hrn)
@@ -72,7 +76,7 @@ def get_credential(api, xrn, type, is_self=False):
     object_hrn = record.get_gid_object().get_hrn()
     print>> sys.stderr , " \r\n    ++  ELSE object_hrn  %s " %(object_hrn)
        
-    rights = api.auth.determine_user_rights(caller_hrn, record)
+    rights = myapi.auth.determine_user_rights(caller_hrn, record)
     print>> sys.stderr , " \r\n    ++  After rights record: %s \r\n ====RIGHTS %s  " %(record , rights)
      
     # make sure caller has rights to this object
@@ -91,7 +95,7 @@ def get_credential(api, xrn, type, is_self=False):
         new_cred.set_expiration(int(record['expires']))
     auth_kind = "authority,ma,sa"
     # Parent not necessary, verify with certs
-    #new_cred.set_parent(api.auth.hierarchy.get_auth_cred(auth_hrn, kind=auth_kind))
+    #new_cred.set_parent(myapi.auth.hierarchy.get_auth_cred(auth_hrn, kind=auth_kind))
     new_cred.encode()
     new_cred.sign()
 
@@ -113,7 +117,7 @@ def resolve(api, xrns, type=None, full=True):
     # hrns at that registry (determined by the known prefix tree).  
     xrn_dict = {}
     print >>sys.stderr, '\r\n REGISTRY MANAGER : resolve xrns '  , xrns #api.__dict__.keys()
-    registries = api.registries
+    registries = myapi.registries
     tree = prefixTree()
     registry_hrns = registries.keys()
     print >>sys.stderr, '\r\n \t\t REGISTRY MANAGER registry_hrns'  , registry_hrns
@@ -137,8 +141,8 @@ def resolve(api, xrns, type=None, full=True):
         # if the best match (longest matching hrn) is not the local registry,
         # forward the request
         xrns = xrn_dict[registry_hrn]
-        if registry_hrn != api.hrn:
-            credential = api.getCredential()
+        if registry_hrn != myapi.hrn:
+            credential = myapi.getCredential()
             peer_records = registries[registry_hrn].Resolve(xrns, credential)
             print >>sys.stderr , '\t\t peer_records ', peer_records
             records.extend([SfaRecord(dict=record).as_dict() for record in peer_records])
@@ -158,8 +162,8 @@ def resolve(api, xrns, type=None, full=True):
         print >>sys.stderr, '\t\t resolve regmanager : rec ', rec    
                    
     if full:
-       print >>sys.stderr, '\r\n \r\n REGISTRY:_FULL', api     
-        api.fill_record_info(local_records)
+       print >>sys.stderr, '\r\n \r\n REGISTRY:_FULL', myapi     
+        myapi.fill_record_info(local_records)
        
   
     # convert local record objects to dicts
@@ -178,7 +182,7 @@ def list(api, xrn, origin_hrn=None):
     # load all know registry names into a prefix tree and attempt to find
     # the longest matching prefix
     records = []
-    registries = api.registries
+    registries = myapi.registries
     registry_hrns = registries.keys()
     tree = prefixTree()
     tree.load(registry_hrns)
@@ -191,14 +195,14 @@ def list(api, xrn, origin_hrn=None):
     # if the best match (longest matching hrn) is not the local registry,
     # forward the request
     records = []    
-    if registry_hrn != api.hrn:
-        credential = api.getCredential()
+    if registry_hrn != myapi.hrn:
+        credential = myapi.getCredential()
         record_list = registries[registry_hrn].List(xrn, credential)
         records = [SfaRecord(dict=record).as_dict() for record in record_list]
     
     # if we still have not found the record yet, try the local registry
     if not records:
-        if not api.auth.hierarchy.auth_exists(hrn):
+        if not myapi.auth.hierarchy.auth_exists(hrn):
             raise MissingAuthority(hrn)
 
         table = SfaTable()
@@ -226,6 +230,7 @@ def register(api, record):
         raise ExistingRecord(hrn)
        
     record = SfaRecord(dict = record)
+<<<<<<< HEAD
     print>>sys.stderr, " \r\n \r\n ----------- REGISTRY_MANAGER_SLAN.PY  register  SfaRecordrecord %s" %(record)
     #record['authority'] = get_authority(record['hrn'])
     record['authority'] = get_authority(hrn)
@@ -234,10 +239,11 @@ def register(api, record):
     #hrn = record['hrn']
     
     #api.auth.verify_object_permission(hrn)
-    api.auth.verify_object_permission( record['hrn'])
-    auth_info = api.auth.get_auth_info(record['authority'])
+    myapi.auth.verify_object_permission( record['hrn'])
+    auth_info = myapi.auth.get_auth_info(record['authority'])
   
     
+
     pub_key = None
     # make sure record has a gid
     if 'gid' not in record:
@@ -250,7 +256,7 @@ def register(api, record):
                 pub_key = record['key']
             pkey = convert_public_key(pub_key)
 
-        gid_object = api.auth.hierarchy.create_gid(urn, uuid, pkey)
+        gid_object = myapi.auth.hierarchy.create_gid(urn, uuid, pkey)
         gid = gid_object.save_to_string(save_parents=True)
         record['gid'] = gid
         record.set_gid(gid)
@@ -260,19 +266,19 @@ def register(api, record):
     if type_of_rec in ["authority"]:   
 
         # update the tree
-        if not api.auth.hierarchy.auth_exists(hrn):
-            api.auth.hierarchy.create_auth(hrn_to_urn(hrn,'authority'))
+        if not myapi.auth.hierarchy.auth_exists(hrn):
+            myapi.auth.hierarchy.create_auth(hrn_to_urn(hrn,'authority'))
 
         # get the GID from the newly created authority
         gid = auth_info.get_gid_object()
         record.set_gid(gid.save_to_string(save_parents=True))
        
-        #pl_record = api.sfa_fields_to_pl_fields(type, hrn, record)
+        #pl_record = myapi.sfa_fields_to_pl_fields(type, hrn, record)
        print>>sys.stderr, " \r\n \r\n ----------- REGISTRY_MANAGER_SLAB.PY  register : type_of_rec in [authority ] sfa_fields_to_pl_fields FIELDS A CHANGER"    
        
-        sites = api.oar.GetSites( [pl_record['login_base']])
+        sites = myapi.oar.GetSites( [pl_record['login_base']])
         if not sites:
-            pointer = api.oar.AddSite( pl_record)
+            pointer = myapi.oar.AddSite( pl_record)
         else:
             pointer = sites[0]['site_id']
 
@@ -281,49 +287,49 @@ def register(api, record):
 
     elif (type_of_rec == "slice"):
         acceptable_fields=['url', 'instantiation', 'name', 'description']
-        pl_record = api.sfa_fields_to_pl_fields(type_of_rec, hrn, record)
+        pl_record = myapi.sfa_fields_to_pl_fields(type_of_rec, hrn, record)
        print>>sys.stderr, " \r\n \r\n ----------- REGISTRY_MANAGER_SLAB.PY  register  slice pl_record %s"%(pl_record)
         for key in pl_record.keys():
             if key not in acceptable_fields:
                 pl_record.pop(key)
-        slices = api.users.GetSlices( [pl_record['name']])
+        slices = myapi.users.GetSlices( [pl_record['name']])
         if not slices:
-             pointer = api.users.AddSlice(pl_record)
+             pointer = myapi.users.AddSlice(pl_record)
         else:
              pointer = slices[0]['slice_id']
         record.set_pointer(pointer)
         record['pointer'] = pointer
 
     elif  (type_of_rec == "user"):
-        persons = api.users.GetPersons( [record['email']]) 
+        persons = myapi.users.GetPersons( [record['email']]) 
        if not persons:
            print>>sys.stderr, "  \r\n \r\n ----------- registry_manager_slab  register NO PERSON ADD TO LDAP?"
       
         #if not persons:
-            #pointer = api.users.AddPerson( dict(record))
+            #pointer = myapi.users.AddPerson( dict(record))
         #else:
             #pointer = persons[0]['person_id']
 
         if 'enabled' in record and record['enabled']:
-            api.users.UpdatePerson( pointer, {'enabled': record['enabled']})
+            myapi.users.UpdatePerson( pointer, {'enabled': record['enabled']})
         # add this persons to the site only if he is being added for the first
         # time by sfa and doesont already exist in plc
         if not persons or not persons[0]['site_ids']:
             login_base = get_leaf(record['authority'])
-            api.users.AddPersonToSite( pointer, login_base)
+            myapi.users.AddPersonToSite( pointer, login_base)
 
         # What roles should this user have?
-        api.users.AddRoleToPerson( 'user', pointer)
+        myapi.users.AddRoleToPerson( 'user', pointer)
         # Add the user's key
         if pub_key:
-            api.users.AddPersonKey( pointer, {'key_type' : 'ssh', 'key' : pub_key})
+            myapi.users.AddPersonKey( pointer, {'key_type' : 'ssh', 'key' : pub_key})
 
     #elif (type == "node"):
-        #pl_record = api.sfa_fields_to_pl_fields(type, hrn, record)
+        #pl_record = myapi.sfa_fields_to_pl_fields(type, hrn, record)
         #login_base = hrn_to_pl_login_base(record['authority'])
-        #nodes = api.oar.GetNodes( [pl_record['hostname']])
+        #nodes = myapi.oar.GetNodes( [pl_record['hostname']])
         #if not nodes:
-            #pointer = api.oar.AddNode(login_base, pl_record)
+            #pointer = myapi.oar.AddNode(login_base, pl_record)
         #else:
             #pointer = nodes[0]['node_id']
 
@@ -333,7 +339,7 @@ def register(api, record):
     #record['record_id'] = record_id
 
     # update membership for researchers, pis, owners, operators
-    api.update_membership(None, record)
+    myapi.update_membership(None, record)
 
     return record.get_gid_object().save_to_string(save_parents=True)
 
@@ -342,7 +348,7 @@ def update(api, record_dict):
     type = new_record['type']
     hrn = new_record['hrn']
     urn = hrn_to_urn(hrn,type)
-    api.auth.verify_object_permission(hrn)
+    myapi.auth.verify_object_permission(hrn)
     table = SfaTable()
     # make sure the record exists
     records = table.findObjects({'type': type, 'hrn': hrn})
@@ -353,7 +359,7 @@ def update(api, record_dict):
 
     # Update_membership needs the membership lists in the existing record
     # filled in, so it can see if members were added or removed
-    api.fill_record_info(record)
+    myapi.fill_record_info(record)
 
     # Use the pointer from the existing record, not the one that the user
     # gave us. This prevents the user from inserting a forged pointer
@@ -361,13 +367,13 @@ def update(api, record_dict):
     # update the PLC information that was specified with the record
 
     if (type == "authority"):
-        api.oar.UpdateSite( pointer, new_record)
+        myapi.oar.UpdateSite( pointer, new_record)
 
     elif type == "slice":
-        pl_record=api.sfa_fields_to_pl_fields(type, hrn, new_record)
+        pl_record=myapi.sfa_fields_to_pl_fields(type, hrn, new_record)
         if 'name' in pl_record:
             pl_record.pop('name')
-            api.users.UpdateSlice( pointer, pl_record)
+            myapi.users.UpdateSlice( pointer, pl_record)
 
     elif type == "user":
         # SMBAKER: UpdatePerson only allows a limited set of fields to be
@@ -380,14 +386,14 @@ def update(api, record_dict):
                        'password', 'phone', 'url', 'bio', 'accepted_aup',
                        'enabled']:
                 update_fields[key] = all_fields[key]
-        api.users.UpdatePerson( pointer, update_fields)
+        myapi.users.UpdatePerson( pointer, update_fields)
 
         if 'key' in new_record and new_record['key']:
             # must check this key against the previous one if it exists
-            persons = api.users.GetPersons( [pointer], ['key_ids'])
+            persons = myapi.users.GetPersons( [pointer], ['key_ids'])
             person = persons[0]
             keys = person['key_ids']
-            keys = api.users.GetKeys( person['key_ids'])
+            keys = myapi.users.GetKeys( person['key_ids'])
             key_exists = False
             if isinstance(new_record['key'], types.ListType):
                 new_key = new_record['key'][0]
@@ -397,29 +403,29 @@ def update(api, record_dict):
             # Delete all stale keys
             for key in keys:
                 if new_record['key'] != key['key']:
-                    api.users.DeleteKey( key['key_id'])
+                    myapi.users.DeleteKey( key['key_id'])
                 else:
                     key_exists = True
             if not key_exists:
-                api.users.AddPersonKey( pointer, {'key_type': 'ssh', 'key': new_key})
+                myapi.users.AddPersonKey( pointer, {'key_type': 'ssh', 'key': new_key})
 
             # update the openssl key and gid
             pkey = convert_public_key(new_key)
             uuid = create_uuid()
-            gid_object = api.auth.hierarchy.create_gid(urn, uuid, pkey)
+            gid_object = myapi.auth.hierarchy.create_gid(urn, uuid, pkey)
             gid = gid_object.save_to_string(save_parents=True)
             record['gid'] = gid
             record = SfaRecord(dict=record)
             table.update(record)
 
     elif type == "node":
-        api.oar.UpdateNode( pointer, new_record)
+        myapi.oar.UpdateNode( pointer, new_record)
 
     else:
         raise UnknownSfaType(type)
 
     # update membership for researchers, pis, owners, operators
-    api.update_membership(record, new_record)
+    myapi.update_membership(record, new_record)
     
     return 1 
 
@@ -438,33 +444,33 @@ def remove(api, xrn, origin_hrn=None):
     record = records[0]
     type = record['type']
 
-    credential = api.getCredential()
-    registries = api.registries
+    credential = myapi.getCredential()
+    registries = myapi.registries
 
     # Try to remove the object from the PLCDB of federated agg.
     # This is attempted before removing the object from the local agg's PLCDB and sfa table
-    if hrn.startswith(api.hrn) and type in ['user', 'slice', 'authority']:
+    if hrn.startswith(myapi.hrn) and type in ['user', 'slice', 'authority']:
         for registry in registries:
-            if registry not in [api.hrn]:
+            if registry not in [myapi.hrn]:
                 try:
                     result=registries[registry].remove_peer_object(credential, record, origin_hrn)
                 except:
                     pass
     if type == "user":
-        persons = api.users.GetPersons(record['pointer'])
+        persons = myapi.users.GetPersons(record['pointer'])
         # only delete this person if he has site ids. if he doesnt, it probably means
         # he was just removed from a site, not actually deleted
         if persons and persons[0]['site_ids']:
-            api.users.DeletePerson(record['pointer'])
+            myapi.users.DeletePerson(record['pointer'])
     elif type == "slice":
-        if api.users.GetSlices( record['pointer']):
-            api.users.DeleteSlice( record['pointer'])
+        if myapi.users.GetSlices( record['pointer']):
+            myapi.users.DeleteSlice( record['pointer'])
     elif type == "node":
-        if api.oar.GetNodes( record['pointer']):
-            api.oar.DeleteNode( record['pointer'])
+        if myapi.oar.GetNodes( record['pointer']):
+            myapi.oar.DeleteNode( record['pointer'])
     elif type == "authority":
-        if api.oar.GetSites( record['pointer']):
-            api.oar.DeleteSite( record['pointer'])
+        if myapi.oar.GetSites( record['pointer']):
+            myapi.oar.DeleteSite( record['pointer'])
     else:
         raise UnknownSfaType(type)
 
diff --git a/sfa/senslab/LDAPapi.py b/sfa/senslab/LDAPapi.py
new file mode 100644 (file)
index 0000000..84528e7
--- /dev/null
@@ -0,0 +1,90 @@
+
+
+
+import ldap
+from sfa.util.config import *
+from sfa.trust.gid import *
+from sfa.trust.hierarchy import *
+from sfa.trust.auth import *
+from sfa.trust.certificate import *
+
+class LDAPapi :
+       def __init__(self, record_filter = None):
+               self.ldapserv=ldap.open("192.168.0.251")
+               self.senslabauth=Hierarchy()
+               config=Config()
+               self.authname=config.SFA_REGISTRY_ROOT_AUTH
+               authinfo=self.senslabauth.get_auth_info(self.authname)
+       
+               self.auth=Auth()
+               gid=authinfo.get_gid_object()
+       
+       def ldapFind(self, record_filter = None, columns=None):
+
+               results = []
+       
+               if 'authority' in record_filter:
+               # ask for authority
+                       if record_filter['authority']==self.authname:
+                               # which is SFA_REGISTRY_ROOT_AUTH
+                               # request all records which are under our authority, ie all ldap entries
+                               ldapfilter="cn=*"
+                       else:
+                               #which is NOT SFA_REGISTRY_ROOT_AUTH
+                               return []
+               else :
+                       if not 'hrn' in record_filter:
+                               print >>sys.stderr,"find : don't know how to handle filter ",record_filter
+                               return []
+                       else:
+                               hrns=[]
+                               h=record_filter['hrn']
+                               if  isinstance(h,list):
+                                       hrns=h
+                               else : 
+                                       hrns.append(h)
+       
+                               ldapfilter="(|"
+                               for hrn in hrns:
+                                       splited_hrn=hrn.split(".")
+                                       if splited_hrn[0] != "SFA_REGISTRY_ROOT_AUTH" :
+                                               print >>sys.stderr,"i know nothing about",hrn
+                                       else :
+                                               login=splited_hrn[1]
+                                               ldapfilter+="(uid="
+                                               ldapfilter+=login
+                                               ldapfilter+=")"
+                               ldapfilter+=")"
+       
+       
+               rindex=self.ldapserv.search("ou=people,dc=senslab,dc=info",ldap.SCOPE_SUBTREE,ldapfilter, ['mail','givenName', 'sn', 'uid','sshPublicKey'])
+               ldapresponse=self.ldapserv.result(rindex,1)
+               for ldapentry in ldapresponse[1]:
+                       hrn=self.authname+"."+ldapentry[1]['uid'][0]
+                       uuid=create_uuid() 
+               
+                       RSA_KEY_STRING=ldapentry[1]['sshPublicKey'][0]
+               
+                       pkey=convert_public_key(RSA_KEY_STRING)
+               
+                       gid=self.senslabauth.create_gid("urn:publicid:IDN+"+self.authname+"+user+"+ldapentry[1]['uid'][0], uuid, pkey, CA=False)
+               
+                       parent_hrn = get_authority(hrn)
+                       parent_auth_info = self.senslabauth.get_auth_info(parent_hrn)
+
+                       results.append(  {      
+                               'type': 'user',
+#                              'email': ldapentry[1]['mail'][0],
+#                              'first_name': ldapentry[1]['givenName'][0],
+#                              'last_name': ldapentry[1]['sn'][0],
+#                              'phone': 'none',
+                               'gid': gid.save_to_string(),
+                               'serial': 'none',
+                               'authority': self.authname,
+                               'peer_authority': '',
+                               'pointer' : '',
+                               'hrn': hrn,
+                               'date_created' : 'none',
+                               'last_updated': 'none'
+                               } )
+               return results
\ No newline at end of file
index f7c9b95..942f2bf 100644 (file)
@@ -5,8 +5,8 @@ import json
 from sfa.senslab.parsing import *
 from sfa.senslab.SenslabImportUsers import *
 
-OARIP='10.127.255.254'
-#OARIP='192.168.0.109'
+#OARIP='10.127.255.254'
+OARIP='192.168.0.109'
 
 
 OARrequests_list = ["GET_version", "GET_timezone", "GET_jobs", "GET_jobs_table", "GET_jobs_details",
diff --git a/sfa/senslab/sfa-bare b/sfa/senslab/sfa-bare
new file mode 100755 (executable)
index 0000000..745955c
--- /dev/null
@@ -0,0 +1,69 @@
+#!/bin/bash
+#
+# sfa  starts sfa service
+#
+# chkconfig: 2345 61 39
+#
+# description:   starts sfa service
+#
+
+# Source config
+[ -f /etc/sfa/sfa_config ] && . /etc/sfa/sfa_config
+
+# source function library
+. /etc/init.d/functions
+
+start() {
+
+    if [ "$SFA_REGISTRY_ENABLED" -eq 1 ]; then
+        action $"SFA Registry" daemon /usr/bin/sfa-server.py -r -d $OPTIONS
+    fi
+
+    if [ "$SFA_AGGREGATE_ENABLED" -eq 1 ]; then
+        action $"SFA Aggregate" daemon /usr/bin/sfa-server.py -a -d $OPTIONS
+    fi
+        
+    if [ "$SFA_SM_ENABLED" -eq 1 ]; then
+        action "SFA SliceMgr" daemon /usr/bin/sfa-server.py -s -d $OPTIONS
+    fi
+
+    if [ "$SFA_FLASHPOLICY_ENABLED" -eq 1 ]; then
+        action "Flash Policy Server" daemon /usr/bin/sfa_flashpolicy.py --file="$SFA_FLASHPOLICY_CONFIG_FILE" --port=$SFA_FLASHPOLICY_PORT -d
+    fi
+
+    RETVAL=$?
+    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/sfa-server.py
+
+}
+
+stop() {
+    action $"Shutting down SFA" killproc sfa-server.py
+    RETVAL=$?
+
+    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sfa-server.py
+}
+
+
+case "$1" in
+    start) start ;;
+    stop) stop ;;
+    reload) reload force ;;
+    restart) stop; start ;;
+    condrestart)
+       if [ -f /var/lock/subsys/sfa-server.py ]; then
+            stop
+            start
+       fi
+       ;;
+    status)
+       status sfa-server.py
+       RETVAL=$?
+       ;;
+    *)
+       echo $"Usage: $0 {start|stop|reload|restart|condrestart|status}"
+       exit 1
+       ;;
+esac
+
+exit $RETVAL
+
index 502f520..62c3af7 100644 (file)
@@ -3,7 +3,7 @@
 #
 # TODO: Use existing PLC database methods? or keep this separate?
 
-import ldap
+
 from sfa.trust.gid import *
 from sfa.util.record import *
 from sfa.util.config import *
@@ -12,14 +12,18 @@ from sfa.trust.hierarchy import *
 from sfa.trust.certificate import *
 from sfa.trust.auth import *
 from sfa.senslab.OARrestapi import *
+from sfa.senslab.LDAPapi import *
 
 class SfaTable(list):
-
+    authname=""
     def __init__(self, record_filter = None):
        self.oar = OARapi()
-        self.ldapserv=ldap.open("192.168.0.251")
+       self.ldap = LDAPapi()
        self.senslabauth=Hierarchy()
-       authinfo=self.senslabauth.get_auth_info("senslab")
+       config=Config()
+       self.authname=config.SFA_REGISTRY_ROOT_AUTH
+       authinfo=self.senslabauth.get_auth_info(self.authname)
+       
        self.auth=Auth()
        gid=authinfo.get_gid_object()
 
@@ -59,85 +63,14 @@ class SfaTable(list):
     def quote(self, value):
         return self.db.quote(value)
     
-    def ldapFind(self, record_filter = None, columns=None):
-
-       results = []
-       
-       #first, ldap for users
-
-       if 'authority' in record_filter:
-               # ask for authority
-               if record_filter['authority']=='senslab':
-                       # which is senslab
-                       # request all records which are under our authority, ie all ldap entries
-                       ldapfilter="cn=*"
-               else:
-                       #which is NOT senslab
-                       return []
-       else :
-               if not 'hrn' in record_filter:
-                       print >>sys.stderr,"find : don't know how to handle filter ",record_filter
-                       return []
-               else:
-                       hrns=[]
-                       h=record_filter['hrn']
-                       if  isinstance(h,list):
-                               hrns=h
-                       else : 
-                               hrns.append(h)
-       
-                       ldapfilter="(|"
-                       for hrn in hrns:
-                               splited_hrn=hrn.split(".")
-                               if splited_hrn[0] != "senslab" :
-                                       print >>sys.stderr,"i know nothing about",hrn
-                               else :
-                                       login=splited_hrn[1]
-                                       ldapfilter+="(uid="
-                                       ldapfilter+=login
-                                       ldapfilter+=")"
-                       ldapfilter+=")"
-       
-       
-       rindex=self.ldapserv.search("ou=people,dc=senslab,dc=info",ldap.SCOPE_SUBTREE,ldapfilter, ['mail','givenName', 'sn', 'uid','sshPublicKey'])
-       ldapresponse=self.ldapserv.result(rindex,1)
-       for ldapentry in ldapresponse[1]:
-               hrn="senslab."+ldapentry[1]['uid'][0]
-               uuid=create_uuid() 
-               
-               RSA_KEY_STRING=ldapentry[1]['sshPublicKey'][0]
-               
-               pkey=convert_public_key(RSA_KEY_STRING)
-               
-               gid=self.senslabauth.create_gid("urn:publicid:IDN+senslab+user+"+ldapentry[1]['uid'][0], uuid, pkey, CA=False)
-               
-               parent_hrn = get_authority(hrn)
-               parent_auth_info = self.senslabauth.get_auth_info(parent_hrn)
-
-               results.append(  {      
-                       'type': 'user',
-#                      'email': ldapentry[1]['mail'][0],
-#                      'first_name': ldapentry[1]['givenName'][0],
-#                      'last_name': ldapentry[1]['sn'][0],
-#                      'phone': 'none',
-                       'gid': gid.save_to_string(),
-                       'serial': 'none',
-                       'authority': 'senslab',
-                       'peer_authority': '',
-                       'pointer' : '',
-                       'hrn': hrn,
-                       'date_created' : 'none',
-                       'last_updated': 'none'
-                       } )
-       return results
-
     def oarFind(self, record_filter = None, columns=None):
        results=[]
        node_ids=[]
 
        if 'authority' in record_filter:
                # ask for authority
-               if record_filter['authority']=='senslab':
+               if record_filter['authority']== self.authname :
                        # which is senslab
                        print>> sys.stderr , "ET MERDE !!!!"
                        node_ids=""
@@ -158,7 +91,7 @@ class SfaTable(list):
        
                        for hrn in hrns:
                                head,sep,tail=hrn.partition(".")
-                               if head != "senslab" :
+                               if head != self.authname :
                                        print >>sys.stderr,"i know nothing about",hrn
                                else :
                                        node_ids.append(tail)
@@ -166,7 +99,7 @@ class SfaTable(list):
        node_list = self.oar.GetNodes( node_ids)
 
        for node in node_list:
-               hrn="senslab."+node['hostname']
+               hrn=self.authname+"."+node['hostname']
                results.append(  {      
                        'type': 'node',
 #                      'email': ldapentry[1]['mail'][0],
@@ -175,7 +108,7 @@ class SfaTable(list):
 #                      'phone': 'none',
 #                      'gid': gid.save_to_string(),
 #                      'serial': 'none',
-                       'authority': 'senslab',
+                       'authority': self.authname,
                        'peer_authority': '',
                        'pointer' : '',
                        'hrn': hrn,
@@ -200,20 +133,20 @@ class SfaTable(list):
                        print >>sys.stderr,"find : don't know how to handle slices yet"
                        return []
                if record_filter['type'] == 'authority':
-                       if  'hrn' in  record_filter and record_filter['hrn']=='senslab':
+                       if  'hrn' in  record_filter and record_filter['hrn']==self.authname:
                                return []
                        else:
                                print >>sys.stderr,"find which authority ?"
                                return []
                if record_filter['type'] == 'user':
-                       return self.ldapFind(record_filter, columns)
+                       return self.ldap.ldapFind(record_filter, columns)
                if record_filter['type'] == 'node':
-                       return self.ldapFind(record_filter, columns)
+                       return self.ldap.ldapFind(record_filter, columns)
                else:
                        print >>sys.stderr,"unknown type to find : ", record_filter['type']
                        return []
        else:
-               allResults = self.ldapFind(record_filter, columns)
+               allResults = self.ldap.ldapFind(record_filter, columns)
                allResults+= self.oarFind(record_filter, columns)
        
        return allResults