- 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(hrn=hrn, gid=slice_gid, type="slice", pointer=slice['slice_id'])
- 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:
- 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]
-
- 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(hrn=hrn, gid=node_gid, type="node", pointer=node['node_id'])
- 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
-
- # Hardcode 'internet2' into the hrn for sites hosting
- # 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"):
- sitename = sitename.replace("ii", "")
- hrn = ".".join([parent_hrn, "internet2", sitename])
- elif sitename.startswith("nlr"):
- hrn = ".".join([parent_hrn, "internet2", sitename])
- sitename = sitename.replace("nlr", "")
-
- trace("Import_Site: importing site " + hrn)
-
- # create the authority
- if not AuthHierarchy.auth_exists(hrn):
- AuthHierarchy.create_auth(hrn)
-
- auth_info = AuthHierarchy.get_auth_info(hrn)
-
- table = get_auth_table(parent_hrn)
-
- auth_record = table.resolve("authority", hrn)
- if not auth_record:
- auth_record = GeniRecord(hrn=hrn, gid=auth_info.get_gid_object(), type="authority", pointer=site['site_id'])
- trace(" inserting authority record for " + hrn)
- table.insert(auth_record)
-
- if 'person_ids' in site:
- for person_id in site['person_ids']:
- persons = shell.GetPersons(plc_auth, [person_id])
- if persons:
- try:
- import_person(hrn, persons[0])
- except Exception, e:
- trace("Failed to import: %s (%s)" % (persons[0], e))
- if 'slice_ids' in site:
- for slice_id in site['slice_ids']:
- slices = shell.GetSlices(plc_auth, [slice_id])
- if slices:
- try:
- import_slice(hrn, slices[0])
- except Exception, e:
- trace("Failed to import: %s (%s)" % (slices[0], e))
- if 'node_ids' in site:
- for node_id in site['node_ids']:
- nodes = shell.GetNodes(plc_auth, [node_id])
- if nodes:
- try:
- import_node(hrn, nodes[0])
- except Exception, e:
- trace("Failed to import: %s (%s)" % (nodes[0], e))
-
-def create_top_level_auth_records(hrn):
- parent_hrn = get_authority(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)
-
- auth_record = table.resolve("authority", hrn)
- if not auth_record:
- auth_record = GeniRecord(hrn=hrn, gid=auth_info.get_gid_object(), type="authority", pointer=-1)
- trace(" inserting authority record for " + hrn)
- table.insert(auth_record)