+ site_hrn = interface_hrn + "." + site['login_base']
+ print "Importing site: %s" % site_hrn
+
+ # 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(interface_hrn, 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(interface_hrn, 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(interface_hrn, 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 == interface_hrn or \
+ record_hrn == root_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 interface_hrn and interface_hrn.endswith('vini') and \
+ record_hrn.endswith("internet2"):
+ continue
+
+ found = False
+
+ if type == 'authority':
+ for site in sites:
+ site_hrn = interface_hrn + "." + site['login_base']
+ if site_hrn == record_hrn and site['site_id'] == record['pointer']:
+ found = True
+ break
+
+ elif type == 'user':
+ login_base = get_leaf(get_authority(record_hrn))
+ username = get_leaf(record_hrn)
+ if login_base in sites_dict:
+ site = sites_dict[login_base]
+ for person in persons:
+ tmp_username = person['email'].split("@")[0]
+ alt_username = person['email'].split("@")[0].replace(".", "_")
+ if username in [tmp_username, alt_username] and \
+ site['site_id'] in person['site_ids'] and \
+ person['person_id'] == record['pointer']:
+ found = True
+ break
+
+ elif type == 'slice':
+ slicename = hrn_to_pl_slicename(record_hrn)
+ for slice in slices:
+ if slicename == slice['name'] and \
+ slice['slice_id'] == record['pointer']:
+ found = True
+ break
+
+ elif type == 'node':
+ login_base = get_leaf(get_authority(record_hrn))
+ nodename = get_leaf(record_hrn)
+ if login_base in sites_dict:
+ site = sites_dict[login_base]
+ for node in nodes:
+ tmp_nodename = node['hostname'].split(".")[0]
+ if tmp_nodename == nodename and \
+ node['site_id'] == site['site_id'] and \
+ node['node_id'] == record['pointer']:
+ found = True
+ break
+ else:
+ continue
+
+ if not found:
+ record_object = existing_records[(record_hrn, type)]
+ sfaImporter.delete_record(record_hrn, type)
+
+ # save pub keys
+ sfaImporter.logger.info('Import: saving current pub keys')
+ save_keys(keys_filename, person_keys)
+