# Get all plc sites
# retrieve only required stuf
sites = shell.GetSites({'peer_id': None, 'enabled' : True},
- ['site_id','login_base','node_ids','slice_ids','person_ids', 'name'])
+ ['site_id','login_base','node_ids','slice_ids','person_ids', 'name', 'hrn'])
# create a hash of sites by login_base
# sites_by_login_base = dict ( [ ( site['login_base'], site ) for site in sites ] )
# Get all plc users
persons = shell.GetPersons({'peer_id': None, 'enabled': True},
- ['person_id', 'email', 'key_ids', 'site_ids', 'role_ids'])
+ ['person_id', 'email', 'key_ids', 'site_ids', 'role_ids', 'hrn'])
# create a hash of persons by person_id
persons_by_id = dict ( [ ( person['person_id'], person) for person in persons ] )
# also gather non-enabled user accounts so as to issue relevant warnings
# create hash by node_id
nodes_by_id = dict ( [ ( node['node_id'], node, ) for node in nodes ] )
# Get all plc slices
- slices = shell.GetSlices( {'peer_id': None}, ['slice_id', 'name', 'person_ids'])
+ slices = shell.GetSlices( {'peer_id': None}, ['slice_id', 'name', 'person_ids', 'hrn'])
# create hash by slice_id
slices_by_id = dict ( [ (slice['slice_id'], slice ) for slice in slices ] )
# isolate special vini case in separate method
self.create_special_vini_record (interface_hrn)
+ # Get top authority record
+ top_auth_record = self.locate_by_type_hrn ('authority', root_auth)
+ admins = []
+
# start importing
for site in sites:
try:
if site['name'].startswith('sfa:') or site_sfa_created == 'True':
continue
- site_hrn = _get_site_hrn(interface_hrn, site)
+ #site_hrn = _get_site_hrn(interface_hrn, site)
+ site_hrn = site['hrn']
# import if hrn is not in list of existing hrns or if the hrn exists
# but its not a site record
- site_record=self.locate_by_type_hrn ('authority', site_hrn)
+ site_record = self.locate_by_type_hrn ('authority', site_hrn)
if not site_record:
try:
urn = hrn_to_urn(site_hrn, 'authority')
auth_info = self.auth_hierarchy.get_auth_info(urn)
site_record = RegAuthority(hrn=site_hrn, gid=auth_info.get_gid_object(),
pointer=site['site_id'],
- authority=get_authority(site_hrn))
+ authority=get_authority(site_hrn),
+ name=site['name'])
site_record.just_created()
global_dbsession.add(site_record)
global_dbsession.commit()
# make sure to NOT run this if anything is wrong
if not proceed: continue
- person_hrn = email_to_hrn(site_hrn, person['email'])
+ #person_hrn = email_to_hrn(site_hrn, person['email'])
+ person_hrn = person['hrn']
+ if person_hrn is None:
+ self.logger.warn("Person %s has no hrn - skipped"%person['email'])
+ continue
# xxx suspicious again
if len(person_hrn) > 64: person_hrn = person_hrn[:64]
person_urn = hrn_to_urn(person_hrn, 'user')
# PI is coded with role_id==20
if 20 in person['role_ids']:
site_pis.append (user_record)
+
+ # PL Admins need to marked as PI of the top authority record
+ if 10 in person['role_ids'] and user_record not in top_auth_record.reg_pis:
+ admins.append(user_record)
+
except:
self.logger.log_exc("PlImporter: failed to import person %d %s"%(person['person_id'],person['email']))
slice = slices_by_id[slice_id]
except:
self.logger.warning ("PlImporter: cannot locate slice_id %s - ignored"%slice_id)
- slice_hrn = slicename_to_hrn(interface_hrn, slice['name'])
+ continue
+ #slice_hrn = slicename_to_hrn(interface_hrn, slice['name'])
+ slice_hrn = slice['hrn']
+ if slice_hrn is None:
+ self.logger.warning("Slice %s has no hrn - skipped"%slice['name'])
+ continue
slice_record = self.locate_by_type_hrn ('slice', slice_hrn)
if not slice_record:
try:
global_dbsession.commit()
slice_record.stale=False
+ # Set PL Admins as PI's of the top authority
+ if admins:
+ top_auth_record.reg_pis = list(set(admins))
+ global_dbsession.commit()
+ self.logger.info('PlImporter: set PL admins %s as PIs of %s'%(admins,top_auth_record.hrn))
+
### remove stale records
# special records must be preserved
system_hrns = [interface_hrn, root_auth, interface_hrn + '.slicemanager']