fix bug in GetVersion(). Use sfa.plc.api.get_server() to establish a connection the...
[sfa.git] / sfa / managers / registry_manager_pl.py
index 4bef95d..6052eee 100644 (file)
@@ -16,7 +16,7 @@ from sfa.util.version import version_core
 
 # The GENI GetVersion call
 def GetVersion(api):
-    peers =dict ([ (peername,v._ServerProxy__host) for (peername,v) in api.registries.items() 
+    peers =dict ([ (peername,v._ServerProxy__host) for (peername,v) in api.registries.iteritems() 
                    if peername != api.hrn])
     xrn=Xrn(api.hrn)
     return version_core({'interface':'registry',
@@ -86,12 +86,14 @@ def get_credential(api, xrn, type, is_self=False):
 
 def resolve(api, xrns, type=None, full=True):
 
-    # load all know registry names into a prefix tree and attempt to find
+    # load all known registry names into a prefix tree and attempt to find
     # the longest matching prefix
     if not isinstance(xrns, types.ListType):
+        if not type:
+            type = Xrn(xrns).get_type()
         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
+    # create a dict where key is a registry hrn and its value is a
     # hrns at that registry (determined by the known prefix tree).  
     xrn_dict = {}
     registries = api.registries
@@ -172,6 +174,18 @@ def list(api, xrn, origin_hrn=None):
     return records
 
 
+def create_gid(api, xrn, cert):
+    # get the authority
+    authority = Xrn(xrn=xrn).get_authority_hrn()
+    auth_info = api.auth.get_auth_info(authority)
+    if not cert:
+        pkey = Keypair(create=True)
+    else:
+        certificate = Certificate(string=cert)
+        pkey = certificate.get_pubkey()    
+    gid = api.auth.hierarchy.create_gid(xrn, create_uuid(), pkey) 
+    return gid.save_to_string(save_parents=True)
+    
 def register(api, record):
 
     hrn, type = record['hrn'], record['type']
@@ -190,7 +204,6 @@ def register(api, record):
     record['authority'] = get_authority(record['hrn'])
     type = record['type']
     hrn = record['hrn']
-    api.auth.verify_object_permission(hrn)
     auth_info = api.auth.get_auth_info(record['authority'])
     pub_key = None
     # make sure record has a gid
@@ -286,7 +299,6 @@ 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)
     table = SfaTable()
     # make sure the record exists
     records = table.findObjects({'type': type, 'hrn': hrn})