using sfa.util.namespace instead of sfa.util.misc
[sfa.git] / sfa / plc / sfaImport.py
index a2ae5e0..399c23a 100644 (file)
@@ -14,10 +14,9 @@ import tempfile
 
 from sfa.util.record import *
 from sfa.util.genitable import GeniTable
-from sfa.util.misc import *
+from sfa.util.namespace import *
 from sfa.util.config import Config
 from sfa.util.report import trace, error
-
 from sfa.trust.certificate import convert_public_key, Keypair
 from sfa.trust.trustedroot import *
 from sfa.trust.hierarchy import *
@@ -50,7 +49,8 @@ def cleanup_string(str):
 
 class sfaImport:
 
-    def __init__(self):
+    def __init__(self, logger=None):
+        self.logger = logger
         self.AuthHierarchy = Hierarchy()
         self.config = Config()
         self.TrustedRoots = TrustedRootList(Config.get_trustedroots_dir(self.config))
@@ -75,6 +75,7 @@ class sfaImport:
         
         # if auth records for this hrn dont exist, create it
         if not AuthHierarchy.auth_exists(hrn):
+            trace("Import: creating top level authorites", self.logger)
             AuthHierarchy.create_auth(hrn)
         
 
@@ -95,7 +96,7 @@ class sfaImport:
         if not auth_record:
             auth_record = GeniRecord(hrn=hrn, gid=auth_info.get_gid_object(), type="authority", pointer=-1)
             auth_record['authority'] = get_authority(auth_record['hrn'])
-            trace("  inserting authority record for " + hrn)
+            trace("Import: inserting authority record for " + hrn, self.logger)
             table.insert(auth_record)
 
 
@@ -107,7 +108,7 @@ class sfaImport:
         if len(hrn) > 64:
             hrn = hrn[:64]
 
-        trace("Import: importing person " + hrn)
+        trace("Import: importing person " + hrn, self.logger)
         key_ids = []
         if 'key_ids' in person and person['key_ids']:
             key_ids = person["key_ids"]
@@ -120,7 +121,7 @@ class sfaImport:
                 pkey = Keypair(create=True)
         else:
             # the user has no keys
-            trace("   person " + hrn + " does not have a PL public key")
+            trace("   person " + hrn + " does not have a PL public key", self.logger)
             # if a key is unavailable, then we still need to put something in the
             # user's GID. So make one up.
             pkey = Keypair(create=True)
@@ -134,7 +135,7 @@ class sfaImport:
         if not existing_records:
             table.insert(person_record)
         else:
-            trace("Import: %s exists, updating " % hrn)
+            trace("Import: %s exists, updating " % hrn, self.logger)
             existing_record = existing_records[0]
             person_record['record_id'] = existing_record['record_id']
             table.update(person_record)
@@ -145,11 +146,11 @@ class sfaImport:
         slicename = cleanup_string(slicename)
 
         if not slicename:
-            error("Import_Slice: failed to parse slice name " + slice['name'])
+            error("Import_Slice: failed to parse slice name " + slice['name'], self.logger)
             return
 
         hrn = parent_hrn + "." + slicename
-        trace("Import: importing slice " + hrn)
+        trace("Import: importing slice " + hrn, self.logger)
 
         pkey = Keypair(create=True)
         slice_gid = AuthHierarchy.create_gid(hrn, create_uuid(), pkey)
@@ -160,7 +161,7 @@ class sfaImport:
         if not existing_records:
             table.insert(slice_record)
         else:
-            trace("Import: %s exists, updating " % hrn)
+            trace("Import: %s exists, updating " % hrn, self.logger)
             existing_record = existing_records[0]
             slice_record['record_id'] = existing_record['record_id']
             table.update(slice_record)
@@ -171,11 +172,11 @@ class sfaImport:
         nodename = cleanup_string(nodename)
         
         if not nodename:
-            error("Import_node: failed to parse node name " + node['hostname'])
+            error("Import_node: failed to parse node name " + node['hostname'], self.logger)
             return
 
         hrn = parent_hrn + "." + nodename
-        trace("Import: importing node " + hrn)
+        trace("Import: importing node " + hrn, self.logger)
         # ASN.1 will have problems with hrn's longer than 64 characters
         if len(hrn) > 64:
             hrn = hrn[:64]
@@ -190,7 +191,7 @@ class sfaImport:
         if not existing_records:
             table.insert(node_record)
         else:
-            trace("Import: %s exists, updating " % hrn)
+            trace("Import: %s exists, updating " % hrn, self.logger)
             existing_record = existing_records[0]
             node_record['record_id'] = existing_record['record_id']
             table.update(node_record)
@@ -209,14 +210,14 @@ class sfaImport:
         # internet2 nodes. This is a special operation for some vini
         # sites only
         if ".vini" in parent_hrn and parent_hrn.endswith('vini'):
-            if sitename.startswith("ii"):
+            if sitename.startswith("i2"):
                 #sitename = sitename.replace("ii", "")
                 hrn = ".".join([parent_hrn, "internet2", sitename])
             elif sitename.startswith("nlr"):
                 #sitename = sitename.replace("nlr", "")
                 hrn = ".".join([parent_hrn, "internet2", sitename])
 
-        trace("Import_Site: importing site " + hrn)
+        trace("Import: importing site " + hrn, self.logger)
 
         # create the authority
         if not AuthHierarchy.auth_exists(hrn):
@@ -231,8 +232,8 @@ class sfaImport:
         if not existing_records:
             table.insert(auth_record)
         else:
-            trace("Import: %s exists, updating " % hrn)
-            existing_record = existing_record[0]
+            trace("Import: %s exists, updating " % hrn, self.logger)
+            existing_record = existing_records[0]
             auth_record['record_id'] = existing_record['record_id']
             table.update(auth_record)
 
@@ -244,4 +245,5 @@ class sfaImport:
         table = GeniTable()
         record_list = table.find({'type': type, 'hrn': hrn})
         for record in record_list:
+            trace("Import: Removing record %s %s" % (type, hrn), self.logger)
             table.remove(record)