Merge branch 'geni-v2' of ssh://git.onelab.eu/git/sfa into geni-v2
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 21 Sep 2012 16:48:32 +0000 (18:48 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 21 Sep 2012 16:48:32 +0000 (18:48 +0200)
sfa/client/client_helper.py
sfa/managers/registry_manager.py
sfa/storage/model.py
sfa/storage/record.py

index d25873f..2117b14 100644 (file)
@@ -1,11 +1,27 @@
-
+###
+#
+# Thierry - 2012 sept 21
+#
+# it seems terribly wrong that the client should decide to use PG- or PL- related code
+# esp. in a context where we're trying to have more and more kinds of testbeds involved
+#
+# also, the 'users' filed that CreateSliver is expecting (the key point here is to get this right)
+# is specified to have at least a urn and a list of keys, both of these being supported natively
+# in the sfa db
+# So long story short, it seems to me that we should have a common code that fills in 'urn' and 'keys'
+# and then code that tentatively tries to add as much extra info that we can get on these users
+#
+# the fact e.g. that PlanetLab insists on getting a first_name and last_name is not
+# exactly consistent with the GENI spec. of CreateSliver
+#
 def pg_users_arg(records):
     users = []  
     for record in records:
         if record['type'] != 'user': 
             continue
-        user = {'urn': record['urn'],
-                'keys': record['keys']}
+        user = {'urn': record['reg-urn'],
+                'keys': record['reg-keys'],
+                }
         users.append(user)
     return users    
 
@@ -14,26 +30,18 @@ def sfa_users_arg (records, slice_record):
     for record in records:
         if record['type'] != 'user': 
             continue
-        try:
-            user = {'urn': record['urn'], #
-# all right, so this is sooo totally wrong
-#                    'keys': record['keys'],
-#                    'email': record['email'], # needed for MyPLC
-#                    'person_id': record['person_id'], # needed for MyPLC
-#                    'first_name': record['first_name'], # needed for MyPLC
-#                    'last_name': record['last_name'], # needed for MyPLC
-#                    'slice_record': slice_record, # needed for legacy refresh peer
-#                    'key_ids': record['key_ids'] # needed for legacy refresh peer
-                    }
-        except:
-            # handle NITOS user args
-            user = {'urn': record['urn'], 
-                    'keys': record['keys'],
-                    'email': record['email'], 
-                    'user_id': record['user_id'], 
-                    'slice_record': slice_record,
-                    }
-            
+        user = {'urn': record['reg-urn'],
+                'keys': record['reg-keys'],
+                'slice_record': slice_record,
+                }
+        # fill as much stuff as possible from planetlab or similar
+        # note that reg-email is not yet available
+        pl_fields = ['email', 'person_id', 'first_name', 'last_name', 'key_ids']
+        nitos_fields = [ 'email', 'user_id' ]
+        extra_fields = list ( set(pl_fields).union(set(nitos_fields)))
+        # try to fill all these in
+        for field in extra_fields:
+            if record.has_key(field): user[field]=record[field]
         users.append(user)
 
     return users
index 81c2bec..b5a63a9 100644 (file)
@@ -18,7 +18,7 @@ from sfa.trust.certificate import Certificate, Keypair, convert_public_key
 from sfa.trust.gid import create_uuid
 
 from sfa.storage.model import make_record, RegRecord, RegAuthority, RegUser, RegSlice, RegKey, \
-    augment_with_urn_and_related_hrns
+    augment_with_sfa_builtins
 from sfa.storage.alchemy import dbsession
 
 class RegistryManager:
@@ -155,7 +155,7 @@ class RegistryManager:
         local_records=local_records.all()
         
         for local_record in local_records:
-            augment_with_urn_and_related_hrns (local_record)
+            augment_with_sfa_builtins (local_record)
 
         logger.info("Resolve, (details=%s,type=%s) local_records=%s "%(details,type,local_records))
         local_dicts = [ record.__dict__ for record in local_records ]
@@ -179,7 +179,7 @@ class RegistryManager:
         # xxx somehow here calling dict(record) issues a weird error
         # however record.todict() seems to work fine
         # records.extend( [ dict(record) for record in local_records ] )
-        records.extend( [ record.todict(exclude_type=RegRecord) for record in local_records ] )
+        records.extend( [ record.todict(exclude_types=[RegRecord,RegKey]) for record in local_records ] )
 
         if not records:
             raise RecordNotFound(str(hrns))
@@ -226,8 +226,9 @@ class RegistryManager:
                 records = dbsession.query(RegRecord).filter(RegRecord.hrn.startswith(hrn))
             else:
                 records = dbsession.query(RegRecord).filter_by(authority=hrn)
-            for record in records: augment_with_urn_and_related_hrns (record)
-            record_dicts=[ record.todict(exclude_type=RegRecord) for record in records ]
+            # so that sfi list can show more than plain names...
+            for record in records: augment_with_sfa_builtins (record)
+            record_dicts=[ record.todict(exclude_types=[RegRecord,RegKey]) for record in records ]
     
         return record_dicts
     
index a2fae0e..3be257f 100644 (file)
@@ -374,10 +374,15 @@ augment_map={'authority': {'reg-pis':'reg_pis',},
                       'reg-slices':'reg_slices_as_researcher',},
              }
 
-def augment_with_urn_and_related_hrns (local_record):
+def augment_with_sfa_builtins (local_record):
     # don't ruin the import of that file in a client world
     from sfa.util.xrn import Xrn
-    local_record.urn=Xrn(xrn=local_record.hrn,type=local_record.type).urn
+    # add a 'urn' field
+    setattr(local_record,'reg-urn',Xrn(xrn=local_record.hrn,type=local_record.type).urn)
+    # users have keys and this is needed to synthesize 'users' sent over to CreateSliver
+    if local_record.type=='user':
+        user_keys = [ key.key for key in local_record.reg_keys ]
+        setattr(local_record, 'reg-keys', user_keys)
     # search in map according to record type
     type_map=augment_map.get(local_record.type,{})
     # use type-dep. map to do the job
index 6e58d10..1aa3aa9 100644 (file)
@@ -34,13 +34,14 @@ class Record:
         return "** undef_datetime **"
     
     # it may be important to exclude relationships
-    def todict (self, exclude_type=None):
+    def todict (self, exclude_types=[]):
         d=self.__dict__
         def exclude (k,v):
             if k.startswith('_'): return True
-            if exclude_type:
-                if isinstance (v,exclude_type): return True
-                if isinstance (v,list) and v and isinstance (v[0],exclude_type) : return True
+            if exclude_types:
+                for exclude_type in exclude_types:
+                    if isinstance (v,exclude_type): return True
+                    if isinstance (v,list) and v and isinstance (v[0],exclude_type) : return True
             return False
         keys=[k for (k,v) in d.items() if not exclude(k,v)]
         return dict ( [ (k,d[k]) for k in keys ] )