in set_pl_info, make usre booleans that are string typed are converted to real boolea...
[sfa.git] / geni / gimport.py
index d37c6f9..5c8f756 100755 (executable)
@@ -22,19 +22,34 @@ from geni.util.hierarchy import *
 from geni.util.record import *
 from geni.util.genitable import *
 from geni.util.misc import *
+from geni.util.config import *
 
-shell = None
+# get PL account settings from config module
+pl_auth = get_pl_auth()
+
+# connect to planetlab
+if "Url" in pl_auth:
+    from geni.util import remoteshell
+    shell = remoteshell.RemoteShell()
+else:
+    import PLC.Shell
+    shell = PLC.Shell.Shell(globals = globals())
 
 ##
 # 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()
 
-keyconvert_fn = "../keyconvert/keyconvert"
+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"
 
 
 def un_unicode(str):
@@ -83,6 +98,8 @@ def connect_shell():
         import PLC.Shell
         shell = PLC.Shell.Shell(globals = globals())
 
+    return shell
+
 def get_auth_table(auth_name):
     AuthHierarchy = Hierarchy()
     auth_info = AuthHierarchy.get_auth_info(auth_name)
@@ -224,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:
@@ -302,7 +319,9 @@ 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)
 
@@ -324,6 +343,8 @@ def main():
 
     process_options()
 
+    print "Base Directory: ", config.GENI_BASE_DIR
+
     AuthHierarchy = Hierarchy()
     TrustedRoots = TrustedRootList()
 
@@ -332,8 +353,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)