- return table
-
-def person_to_hrn(parent_hrn, person):
- # 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)
-
- hrn = parent_hrn + "." + personname
- return hrn
-
-def import_person(parent_hrn, person):
- AuthHierarchy = Hierarchy()
- hrn = person_to_hrn(parent_hrn, person)
-
- # ASN.1 will have problems with hrn's longer than 64 characters
- if len(hrn) > 64:
- hrn = hrn[:64]
-
- report.trace("Import: importing person " + hrn)
-
- table = get_auth_table(parent_hrn)
-
- key_ids = []
- if 'key_ids' in person:
- key_ids = person["key_ids"]
-
- # get the user's private key from the SSH keys they have uploaded
- # to planetlab
- keys = shell.GetKeys(pl_auth, key_ids)
- key = keys[0]['key']
- pkey =convert_public_key(key)
- else:
- # the user has no keys
- report.trace(" person " + hrn + " does not have a PL public key")
-
- # 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)
-
- # create the gid
- person_gid = AuthHierarchy.create_gid(hrn, create_uuid(), pkey)
- person_record = table.resolve("user", hrn)
- if not person_record:
- report.trace(" inserting user record for " + hrn)
- person_record = GeniRecord(name=hrn, gid=person_gid, type="user", pointer=person['person_id'])
- table.insert(person_record)
- else:
- report.trace(" updating user record for " + hrn)
- person_record = GeniRecord(name=hrn, gid=person_gid, type="user", pointer=person['person_id'])
- table.update(person_record)
-
-def import_slice(parent_hrn, slice):
- AuthHierarchy = Hierarchy()
- slicename = slice['name'].split("_",1)[-1]
- slicename = cleanup_string(slicename)
-
- if not slicename:
- report.error("Import_Slice: failed to parse slice name " + slice['name'])
- return
-
- hrn = parent_hrn + "." + slicename
- report.trace("Import: importing slice " + hrn)
-
- table = get_auth_table(parent_hrn)
-
- slice_record = table.resolve("slice", hrn)
- if not slice_record:
- pkey = Keypair(create=True)
- slice_gid = AuthHierarchy.create_gid(hrn, create_uuid(), pkey)
- slice_record = GeniRecord(name=hrn, gid=slice_gid, type="slice", pointer=slice['slice_id'])
- report.trace(" inserting slice record for " + hrn)
- table.insert(slice_record)
-
-def import_node(parent_hrn, node):
- AuthHierarchy = Hierarchy()
- nodename = node['hostname'].split(".")[0]
- nodename = cleanup_string(nodename)
-
- if not nodename:
- report.error("Import_node: failed to parse node name " + node['hostname'])
- return
-
- hrn = parent_hrn + "." + nodename
-
- # ASN.1 will have problems with hrn's longer than 64 characters
- if len(hrn) > 64:
- hrn = hrn[:64]
-
- report.trace("Import: importing node " + hrn)
-
- table = get_auth_table(parent_hrn)
-
- node_record = table.resolve("node", hrn)
- if not node_record:
- pkey = Keypair(create=True)
- node_gid = AuthHierarchy.create_gid(hrn, create_uuid(), pkey)
- node_record = GeniRecord(name=hrn, gid=node_gid, type="node", pointer=node['node_id'])
- report.trace(" inserting node record for " + hrn)
- table.insert(node_record)
-
-def import_site(parent_hrn, site):
- AuthHierarchy = Hierarchy()
- sitename = site['login_base']
- sitename = cleanup_string(sitename)
-
- hrn = parent_hrn + "." + sitename