symbols starting with __ are reserved
[sfa.git] / sfa / importer / sfaImport.py
index 3f8284d..e54bec7 100644 (file)
@@ -16,7 +16,8 @@ from sfa.trust.certificate import convert_public_key, Keypair
 from sfa.trust.trustedroots import TrustedRoots
 from sfa.trust.hierarchy import Hierarchy
 from sfa.trust.gid import create_uuid
-from sfa.storage.persistentobjs import RegRecord
+from sfa.storage.persistentobjs import RegRecord, RegAuthority, RegUser
+from sfa.storage.persistentobjs import RegTmpAuthSa, RegTmpAuthAm, RegTmpAuthSm
 from sfa.storage.alchemy import dbsession
 
 def _un_unicode(str):
@@ -65,6 +66,9 @@ class sfaImport:
 
         # create interface records
         self.logger.info("Import: creating interface records")
+# xxx authority+ turning off the creation of authority+*
+# in fact his is required - used in SfaApi._getCredentialRaw
+# that tries to locate 'authority+sa'
         self.create_interface_records()
 
         # add local root authority's cert  to trusted list
@@ -87,12 +91,14 @@ class sfaImport:
         self.AuthHierarchy.create_top_level_auth(hrn)    
         # create the db record if it doesnt already exist    
         auth_info = self.AuthHierarchy.get_auth_info(hrn)
-        auth_record = RegRecord("authority", hrn=hrn, gid=auth_info.get_gid_object(), 
-                                authority=get_authority(hrn))
+        auth_record = RegAuthority()
+        auth_record.hrn=hrn
+        auth_record.gid=auth_info.get_gid_object()
+        auth_record.authority=get_authority(hrn)
         auth_record.just_created()
-        self.logger.info("Import: importing auth %s " % auth_record)
         dbsession.add (auth_record)
         dbsession.commit()
+        self.logger.info("Import: imported authority (parent) %s " % auth_record)
 
     def create_sm_client_record(self):
         """
@@ -105,13 +111,16 @@ class sfaImport:
             self.AuthHierarchy.create_auth(urn)
 
         auth_info = self.AuthHierarchy.get_auth_info(hrn)
-        user_record = RegRecord("user", hrn=hrn, gid=auth_info.get_gid_object(), \
-                                   authority=get_authority(hrn))
+        user_record = RegUser()
+        user_record.hrn=hrn
+        user_record.gid=auth_info.get_gid_object()
+        user_record.authority=get_authority(hrn)
         user_record.just_created()
-        self.logger.info("Import: importing user %s " % user_record)
         dbsession.add (user_record)
         dbsession.commit()
+        self.logger.info("Import: importing user (slicemanager) %s " % user_record)
 
+# xxx authority+ - this is currently turned off 
     def create_interface_records(self):
         """
         Create a record for each SFA interface
@@ -119,21 +128,29 @@ class sfaImport:
         # just create certs for all sfa interfaces even if they
         # arent enabled
         hrn = self.config.SFA_INTERFACE_HRN
-        interfaces = ['authority+sa', 'authority+am', 'authority+sm']
+        reg_classes_info = [ (RegTmpAuthSa, 'authority+sa'),
+                          (RegTmpAuthAm, 'authority+am'),
+                          (RegTmpAuthSm, 'authority+sm'), ]
+        # interfaces = ['authority+sa', 'authority+am', 'authority+sm']
         auth_info = self.AuthHierarchy.get_auth_info(hrn)
         pkey = auth_info.get_pkey_object()
-        for interface in interfaces:
+        for (reg_class, interface) in reg_classes_info:
             urn = hrn_to_urn(hrn, interface)
             gid = self.AuthHierarchy.create_gid(urn, create_uuid(), pkey)
-            interface_record = RegRecord(interface, hrn=hrn, gid = gid, 
-                                         authority=get_authority(hrn))
+            # xxx this should probably use a RegAuthority, or a to-be-defined RegPeer object
+            # but for now we have to preserve the authority+<> stuff
+            interface_record = reg_class()
+            #interface_record = RegAuthority()
+            interface_record.hrn=hrn
+            interface_record.gid= gid
+            interface_record.authority=get_authority(hrn)
             interface_record.just_created()
-            self.logger.info("Import: importing %s " % interface_record)
             dbsession.add (interface_record)
             dbsession.commit()
+            self.logger.info("Import: imported authority (%s) %s " % (interface,interface_record))
              
     def delete_record(self, hrn, type):
         # delete the record
         for rec in dbsession.query(RegRecord).filter_by(type=type,hrn=hrn):
-           del rec
+           dbsession.delete(rec)
         dbsession.commit()