remove sfa upcalls
[plcapi.git] / PLC / SFA.py
index efd2aa1..edff676 100644 (file)
@@ -2,9 +2,10 @@ import traceback
 from types import StringTypes
 from PLC.Sites import Sites
 try:
-    from sfa.plc.api import GeniAPI
+    from sfa.util.geniclient import *
+    from sfa.util.config import *
+    from sfa.trust.credential import *         
     from sfa.plc.sfaImport import cleanup_string
-    from sfa.server.registry import Registries
     from sfa.util.record import *
     from sfa.trust.hierarchy import *
     from sfa.util.misc import *
@@ -45,13 +46,14 @@ class SFA:
     
         # get a connection to our local sfa registry
         # and a valid credential
-        self.sfa_api = GeniAPI(key_file = key_file, cert_file = cert_file)
-        self.sfa_api.interface = "plcapi"
-        registries = Registries(self.sfa_api)
-        self.registry = registries[self.sfa_api.hrn]
-        self.credential = self.sfa_api.getCredential()
-        self.authority = self.sfa_api.hrn
-        
+        config = Config()
+        self.authority = config.SFA_INTERFACE_HRN
+        url = 'http://%s:%s/' %(config.SFA_REGISTRY_HOST, config.SFA_REGISTRY_PORT) 
+        self.registry = GeniClient(url, key_file, cert_file)
+        #self.sfa_api = GeniAPI(key_file = key_file, cert_file = cert_file)
+        #self.credential = self.sfa_api.getCredential() 
+        cred_file = '/etc/sfa/slicemgr.' + self.authority + '.authority.cred'
+        self.credential = Credential(filename = cred_file)   
 
     def get_login_base(self, site_id):
         sites = Sites(self.api, [site_id], ['login_base'])
@@ -103,11 +105,11 @@ class SFA:
         check if the record (hrn and type) already exist in our sfa db
         """
         exists = False
-        
         # list is quicker than resolve
         parent_hrn = get_authority(hrn)
         if not parent_hrn: parent_hrn = hrn
-        records = self.registry.list(self.credential, parent_hrn)
+        #records = self.registry.list(self.credential, parent_hrn)
+        records = self.registry.resolve(self.credential, hrn)
         for record in records: 
             if record['type'] == type and record['hrn'] == hrn:
                 exists = True
@@ -136,7 +138,7 @@ class SFA:
             # object 
             object['hrn'] = self.get_object_hrn(type, object, self.authority, login_base)   
             object['type'] = type
-            if type in ['user', 'person']:
+            if type in ['user']:
                 record = UserRecord(dict=object)
 
             elif type in ['slice']:
@@ -154,6 +156,8 @@ class SFA:
             # add the record to sfa
             if not self.sfa_record_exists(object['hrn'], type):
                 self.registry.register(self.credential, record)
+            else:
+                self.registry.update(self.credential, record)
 
     @wrap_exception
     @required_packages_imported