creating tag sfa-0.9-11
[sfa.git] / sfa / managers / registry_manager_pl.py
index ec56127..2486738 100644 (file)
@@ -1,6 +1,5 @@
 import types
 import time 
-from sfa.server.registry import Registries
 from sfa.util.prefixTree import prefixTree
 from sfa.util.record import SfaRecord
 from sfa.util.table import SfaTable
@@ -32,6 +31,9 @@ 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)
+    if record['type']=='user':
+       if not record['enabled']:
+          raise AccountNotEnabled(": PlanetLab account %s is not enabled. Please contact your site PI" %(record['email']))
 
     # get the callers gid
     # if this is a self cred the record's gid is the caller's gid
@@ -63,23 +65,23 @@ def get_credential(api, xrn, type, is_self=False):
 
     return new_cred.save_to_string(save_parents=True)
 
-def resolve(api, xrns, type=None, origin_hrn=None):
+def resolve(api, xrns, type=None, origin_hrn=None, full=True):
 
     # load all know registry names into a prefix tree and attempt to find
     # the longest matching prefix
-    if not isinstance(hrns, types.ListType):
+    if not isinstance(xrns, types.ListType):
         xrns = [xrns]
-    
+    hrns = [urn_to_hrn(xrn)[0] for xrn in xrns] 
     # create a dict whre key is an registry hrn and its value is a
     # hrns at that registry (determined by the known prefix tree).  
     xrn_dict = {}
-    registries = Registries(api)
+    registries = api.registries
     tree = prefixTree()
     registry_hrns = registries.keys()
     tree.load(registry_hrns)
     for xrn in xrns:
         registry_hrn = tree.best_match(urn_to_hrn(xrn)[0])
-        if registry_hrn not in hrn_dict:
+        if registry_hrn not in xrn_dict:
             xrn_dict[registry_hrn] = []
         xrn_dict[registry_hrn].append(xrn)
         
@@ -100,19 +102,15 @@ def resolve(api, xrns, type=None, origin_hrn=None):
 
     # try resolving the remaining unfound records at the local registry
     remaining_hrns = set(hrns).difference([record['hrn'] for record in records])
+    # convert set to list
     remaining_hrns = [hrn for hrn in remaining_hrns] 
     table = SfaTable()
     local_records = table.findObjects({'hrn': remaining_hrns})
-    for record in local_records:
-        try:
-            api.fill_record_info(record)
-            records.append(dict(record))
-        except PlanetLabRecordDoesNotExist:
-            # silently drop the ones that are missing in PL
-            print >> log, "ignoring SFA record ", record['hrn'], \
-                              " because pl record does not exist"    
-            table.remove(record)
-
+    if full:
+        api.fill_record_info(local_records)
+    
+    # convert local record objects to dicts
+    records.extend([dict(record) for record in local_records])
     if not records:
         raise RecordNotFound(str(hrns))
 
@@ -121,17 +119,17 @@ def resolve(api, xrns, type=None, origin_hrn=None):
 
     return records
 
-def list(api, xrn):
+def list(api, xrn, origin_hrn=None):
     hrn, type = urn_to_hrn(xrn)
     # load all know registry names into a prefix tree and attempt to find
     # the longest matching prefix
     records = []
-    registries = Registries(api)
+    registries = api.registries
     registry_hrns = registries.keys()
     tree = prefixTree()
     tree.load(registry_hrns)
     registry_hrn = tree.best_match(hrn)
-    
+   
     #if there was no match then this record belongs to an unknow registry
     if not registry_hrn:
         raise MissingAuthority(xrn)
@@ -216,13 +214,13 @@ def register(api, record):
         for key in pl_record.keys():
             if key not in acceptable_fields:
                 pl_record.pop(key)
-            slices = api.plshell.GetSlices(api.plauth, [pl_record['name']])
-            if not slices:
-                pointer = api.plshell.AddSlice(api.plauth, pl_record)
-            else:
-                pointer = slices[0]['slice_id']
-            record.set_pointer(pointer)
-            record['pointer'] = pointer
+        slices = api.plshell.GetSlices(api.plauth, [pl_record['name']])
+        if not slices:
+             pointer = api.plshell.AddSlice(api.plauth, pl_record)
+        else:
+             pointer = slices[0]['slice_id']
+        record.set_pointer(pointer)
+        record['pointer'] = pointer
 
     elif  (type == "user"):
         persons = api.plshell.GetPersons(api.plauth, [record['email']])
@@ -367,7 +365,7 @@ def remove(api, xrn, type, origin_hrn=None):
     type = record['type']
 
     credential = api.getCredential()
-    registries = Registries(api)
+    registries = api.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