small bugfix. NT.
[sfa.git] / sfa / managers / registry_manager_slab.py
index 2cde76c..a13eb8a 100644 (file)
@@ -16,7 +16,7 @@ from sfa.trust.gid import create_uuid
 from sfa.util.version import version_core
 from sfa.senslab.api import *
 
-myapi=SfaAPI()
+myapi=SfaAPI(interface='registry')
 # The GENI GetVersion call
 def GetVersion(api):
     
@@ -197,7 +197,13 @@ def list(api, xrn, origin_hrn=None):
     records = []    
     if registry_hrn != myapi.hrn:
         credential = myapi.getCredential()
-        record_list = registries[registry_hrn].List(xrn, credential)
+       print>>sys.stderr, "Registries : ", registries
+        #record_list = registries[registry_hrn].List(xrn, credential)
+       
+       interface=registries[registry_hrn]
+       server=api.get_server(interface,credential)
+       records= server.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
@@ -213,26 +219,37 @@ def list(api, xrn, origin_hrn=None):
 
 def register(api, record):
 
-
-    hrn, type = record['hrn'], record['type']
-    urn = hrn_to_urn(hrn,type)
+    hrn = str(record['hrn']).strip("['']")
+    type_of_rec = str( record['type']).strip("['']")
+  
+    urn = hrn_to_urn(hrn,type_of_rec)
     # validate the type
-    print>>sys.stderr, " \r\n \r\n ----------- registry_manager_sl  register hrn %s"%(hrn)
-    if type not in ['authority', 'slice', 'node', 'user']:
-        raise UnknownSfaType(type) 
+    if type_of_rec not in ['authority', 'slice', 'node', 'user']:
+        raise UnknownSfaType(type_of_rec
     
     # check if record already exists
     table = SfaTable()
-    existing_records = table.find({'type': type, 'hrn': hrn})
+    existing_records = table.find({'type': type_of_rec, 'hrn': hrn})
     if existing_records:
         raise ExistingRecord(hrn)
        
     record = SfaRecord(dict = record)
-    record['authority'] = get_authority(record['hrn'])
-    type = record['type']
-    hrn = record['hrn']
-    myapi.auth.verify_object_permission(hrn)
+
+    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)
+    
+    #type_of_rec = record['type']
+    #hrn = record['hrn']
+    
+    #api.auth.verify_object_permission(hrn)
+    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:
@@ -249,8 +266,11 @@ def register(api, record):
         gid = gid_object.save_to_string(save_parents=True)
         record['gid'] = gid
         record.set_gid(gid)
+       print>>sys.stderr, " \r\n \r\n ----------- REGISTRY_MANAGER_SLAB.PY   record['gid']  %s" %(record['gid'])   
+       print>>sys.stderr, " \r\n \r\n ----------- REGISTRY_MANAGER_SLAB.PY  register type_of_rec %s"%(type_of_rec)
+       
+    if type_of_rec in ["authority"]:   
 
-    if type in ["authority"]:
         # update the tree
         if not myapi.auth.hierarchy.auth_exists(hrn):
             myapi.auth.hierarchy.create_auth(hrn_to_urn(hrn,'authority'))
@@ -258,7 +278,10 @@ def register(api, record):
         # 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 = myapi.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 = myapi.oar.GetSites( [pl_record['login_base']])
         if not sites:
             pointer = myapi.oar.AddSite( pl_record)
@@ -268,10 +291,10 @@ def register(api, record):
         record.set_pointer(pointer)
         record['pointer'] = pointer
 
-    elif (type == "slice"):
+    elif (type_of_rec == "slice"):
         acceptable_fields=['url', 'instantiation', 'name', 'description']
-        pl_record = myapi.sfa_fields_to_pl_fields(type, hrn, record)
-       print>>sys.stderr, " \r\n \r\n ----------- registry_manager_slab register  slice pl_record %s"%(pl_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)
@@ -283,7 +306,7 @@ def register(api, record):
         record.set_pointer(pointer)
         record['pointer'] = pointer
 
-    elif  (type == "user"):
+    elif  (type_of_rec == "user"):
         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?"
@@ -318,8 +341,8 @@ def register(api, record):
 
     ##record['pointer'] = pointer
     ##record.set_pointer(pointer)
-    record_id = table.insert(record)
-    record['record_id'] = record_id
+    #record_id = table.insert(record)
+    #record['record_id'] = record_id
 
     # update membership for researchers, pis, owners, operators
     myapi.update_membership(None, record)