+ site_hrn = import_auth + "." + site['login_base']
+ # import if hrn is not in list of existing hrns or if the hrn exists
+ # but its not a site record
+ if site_hrn not in existing_hrns or \
+ (site_hrn, 'authority') not in existing_records:
+ site_hrn = sfaImporter.import_site(import_auth, site)
+
+ # import node records
+ for node_id in site['node_ids']:
+ if node_id not in nodes_dict:
+ continue
+ node = nodes_dict[node_id]
+ hrn = hostname_to_hrn(import_auth, site['login_base'], node['hostname'])
+ if hrn not in existing_hrns or \
+ (hrn, 'node') not in existing_records:
+ sfaImporter.import_node(site_hrn, node)
+
+ # import slices
+ for slice_id in site['slice_ids']:
+ if slice_id not in slices_dict:
+ continue
+ slice = slices_dict[slice_id]
+ hrn = slicename_to_hrn(import_auth, slice['name'])
+ if hrn not in existing_hrns or \
+ (hrn, 'slice') not in existing_records:
+ sfaImporter.import_slice(site_hrn, slice)
+
+ # import persons
+ for person_id in site['person_ids']:
+ if person_id not in persons_dict:
+ continue
+ person = persons_dict[person_id]
+ hrn = email_to_hrn(site_hrn, person['email'])
+ old_keys = []
+ new_keys = []
+ if person_id in old_person_keys:
+ old_keys = old_person_keys[person_id]
+ if person_id in person_keys:
+ new_keys = person_keys[person_id]
+ update_record = False
+ for key in new_keys:
+ if key not in old_keys:
+ update_record = True
+
+ if hrn not in existing_hrns or \
+ (hrn, 'user') not in existing_records or update_record:
+ sfaImporter.import_person(site_hrn, person)
+
+ # remove stale records
+ for (record_hrn, type) in existing_records.keys():
+ record = existing_records[(record_hrn, type)]
+ # if this is the interface name dont do anything
+ if record_hrn == import_auth or record['peer_authority']:
+ continue
+ # dont delete vini's internet2 placeholdder record
+ # normally this would be deleted becuase it does not have a plc record
+ if ".vini" in import_auth and import_auth.endswith('vini') and \
+ record_hrn.endswith("internet2"):
+ continue
+
+ found = False
+
+ if type == 'authority':
+ for site in sites:
+ site_hrn = import_auth + "." + site['login_base']
+ if site_hrn == record_hrn and site['site_id'] == record['pointer']:
+ found = True
+ break