switch from sa/ma to authority, fix update_membership_list
[sfa.git] / geni / gimport.py
index 45dbb44..ef6534c 100755 (executable)
@@ -38,12 +38,17 @@ else:
 ##
 # Two authorities are specified: the root authority and the level1 authority.
 
-root_auth = "plc"
-level1_auth = None
+#root_auth = "plc"
+#level1_auth = None
 
 #root_auth = "planetlab"
 #level1_auth = "planetlab.us"
 config = Config()
+
+root_auth = config.GENI_REGISTRY_ROOT_AUTH
+level1_auth = config.GENI_REGISTRY_LEVEL1_AUTH
+if not level1_auth or level1_auth in ['']:
+    level1_auth = None
 keyconvert_fn = config.GENI_BASE_DIR + os.sep + "keyconvert/keyconvert"
 
 
@@ -236,7 +241,7 @@ def import_slice(parent_hrn, slice):
 
 def import_node(parent_hrn, node):
     AuthHierarchy = Hierarchy()
-    nodename = node['hostname']
+    nodename = node['hostname'].split(".")[0]
     nodename = cleanup_string(nodename)
 
     if not nodename:
@@ -278,17 +283,11 @@ def import_site(parent_hrn, site):
 
     table = get_auth_table(parent_hrn)
 
-    sa_record = table.resolve("sa", hrn)
-    if not sa_record:
-        sa_record = GeniRecord(name=hrn, gid=auth_info.get_gid_object(), type="sa", pointer=site['site_id'])
-        report.trace("  inserting sa record for " + hrn)
-        table.insert(sa_record)
-
-    ma_record = table.resolve("ma", hrn)
-    if not ma_record:
-        ma_record = GeniRecord(name=hrn, gid=auth_info.get_gid_object(), type="ma", pointer=site['site_id'])
-        report.trace("  inserting ma record for " + hrn)
-        table.insert(ma_record)
+    auth_record = table.resolve("authority", hrn)
+    if not auth_record:
+        auth_record = GeniRecord(name=hrn, gid=auth_info.get_gid_object(), type="authority", pointer=site['site_id'])
+        report.trace("  inserting authority record for " + hrn)
+        table.insert(auth_record)
 
     for person_id in site['person_ids']:
         persons = shell.GetPersons(pl_auth, [person_id])
@@ -314,21 +313,17 @@ def import_site(parent_hrn, site):
 
 def create_top_level_auth_records(hrn):
     parent_hrn = get_authority(hrn)
-    print hrn, ":", parent_hrn 
+    print hrn, ":", parent_hrn
+    if not parent_hrn:
+        parent_hrn = hrn       
     auth_info = AuthHierarchy.get_auth_info(parent_hrn)
     table = get_auth_table(parent_hrn)
 
-    sa_record = table.resolve("sa", hrn)
-    if not sa_record:
-        sa_record = GeniRecord(name=hrn, gid=auth_info.get_gid_object(), type="sa", pointer=-1)
-        report.trace("  inserting sa record for " + hrn)
-        table.insert(sa_record)
-
-    ma_record = table.resolve("ma", hrn)
-    if not ma_record:
-        ma_record = GeniRecord(name=hrn, gid=auth_info.get_gid_object(), type="ma", pointer=-1)
-        report.trace("  inserting ma record for " + hrn)
-        table.insert(ma_record)
+    auth_record = table.resolve("authority", hrn)
+    if not auth_record:
+        auth_record = GeniRecord(name=hrn, gid=auth_info.get_gid_object(), type="authority", pointer=-1)
+        report.trace("  inserting authority record for " + hrn)
+        table.insert(auth_record)
 
 def main():
     global AuthHierarchy
@@ -336,6 +331,8 @@ def main():
 
     process_options()
 
+    print "Base Directory: ", config.GENI_BASE_DIR
+
     AuthHierarchy = Hierarchy()
     TrustedRoots = TrustedRootList()
 
@@ -344,8 +341,7 @@ def main():
     if not AuthHierarchy.auth_exists(root_auth):
         AuthHierarchy.create_auth(root_auth)
 
-    #create_top_level_auth_records(root_auth)
-
+    create_top_level_auth_records(root_auth)
     if level1_auth:
         if not AuthHierarchy.auth_exists(level1_auth):
             AuthHierarchy.create_auth(level1_auth)