X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=geni%2Fgimport.py;h=5c8f756f089d1c4e94d345f500b266a9439e8a86;hb=5a04ddd0df353a10f926ceaddfddd88f17997e85;hp=31e3faeb64e009cc98efb1bd51b251d1650e2242;hpb=3f02043626b0511a3b92406411eb44810e607542;p=sfa.git diff --git a/geni/gimport.py b/geni/gimport.py index 31e3faeb..5c8f756f 100755 --- a/geni/gimport.py +++ b/geni/gimport.py @@ -16,20 +16,40 @@ import getopt import sys import tempfile -from cert import * -from trustedroot import * -from hierarchy import * -from record import * -from genitable import * -from misc import * - -shell = None +from geni.util.cert import * +from geni.util.trustedroot import * +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 * + +# 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 = "planetlab" -level1_auth = "planetlab.us" +#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" def un_unicode(str): @@ -72,12 +92,14 @@ def connect_shell(): # connect to planetlab if "Url" in pl_auth: - import remoteshell + from geni.util import remoteshell shell = remoteshell.RemoteShell() else: 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) @@ -110,7 +132,11 @@ def get_pl_pubkey(key_id): os.write(ssh_f, key_str) os.close(ssh_f) - cmd = "../keyconvert/keyconvert " + ssh_fn + " " + ssl_fn + if not os.path.exists(keyconvert_fn): + report.trace(" keyconvert utility " + str(keyconvert_fn) + " does not exist"); + sys.exit(-1) + + cmd = keyconvert_fn + " " + ssh_fn + " " + ssl_fn print cmd os.system(cmd) @@ -137,7 +163,11 @@ def get_pl_pubkey(key_id): return None def person_to_hrn(parent_hrn, person): - personname = person['last_name'] + "_" + person['first_name'] + # the old way - Lastname_Firstname + #personname = person['last_name'] + "_" + person['first_name'] + + # the new way - use email address up to the "@" + personname = person['email'].split("@")[0] personname = cleanup_string(personname) @@ -211,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: @@ -268,21 +298,30 @@ def import_site(parent_hrn, site): for person_id in site['person_ids']: persons = shell.GetPersons(pl_auth, [person_id]) if persons: - import_person(hrn, persons[0]) - + try: + import_person(hrn, persons[0]) + except: + report.trace("Failed to import: %s" % persons[0]) for slice_id in site['slice_ids']: slices = shell.GetSlices(pl_auth, [slice_id]) if slices: - import_slice(hrn, slices[0]) - + try: + import_slice(hrn, slices[0]) + except: + report.trace("Failed to import: %s" % slices[0]) for node_id in site['node_ids']: nodes = shell.GetNodes(pl_auth, [node_id]) if nodes: - import_node(hrn, nodes[0]) + try: + import_node(hrn, nodes[0]) + except: + report.trace("Failed to import: %s" % nodes[0]) 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) @@ -304,6 +343,8 @@ def main(): process_options() + print "Base Directory: ", config.GENI_BASE_DIR + AuthHierarchy = Hierarchy() TrustedRoots = TrustedRootList() @@ -311,10 +352,15 @@ def main(): if not AuthHierarchy.auth_exists(root_auth): AuthHierarchy.create_auth(root_auth) - #create_top_level_auth_records(root_auth) - if not AuthHierarchy.auth_exists(level1_auth): - AuthHierarchy.create_auth(level1_auth) - create_top_level_auth_records(level1_auth) + + create_top_level_auth_records(root_auth) + if level1_auth: + if not AuthHierarchy.auth_exists(level1_auth): + AuthHierarchy.create_auth(level1_auth) + create_top_level_auth_records(level1_auth) + import_auth = level1_auth + else: + import_auth = root_auth print "Import: adding", root_auth, "to trusted list" root = AuthHierarchy.get_auth_info(root_auth) @@ -324,7 +370,7 @@ def main(): sites = shell.GetSites(pl_auth) for site in sites: - import_site(level1_auth, site) + import_site(import_auth, site) if __name__ == "__main__": main()