from sfa.util.config import Config
from sfa.util.xrn import Xrn, get_leaf, get_authority, hrn_to_urn
-from sfa.util.plxrn import hostname_to_hrn, slicename_to_hrn, email_to_hrn, hrn_to_pl_slicename
from sfa.trust.gid import create_uuid
from sfa.trust.certificate import convert_public_key, Keypair
from sfa.storage.alchemy import dbsession
from sfa.storage.model import RegRecord, RegAuthority, RegSlice, RegNode, RegUser, RegKey
-from sfa.plc.plshell import PlShell
+from sfa.planetlab.plshell import PlShell
+from sfa.planetlab.plxrn import hostname_to_hrn, slicename_to_hrn, email_to_hrn, hrn_to_pl_slicename
def _get_site_hrn(interface_hrn, site):
# Hardcode 'internet2' into the hrn for sites hosting
def locate_by_type_pointer (self, type, pointer):
return self.records_by_type_pointer.get ( (type, pointer), None)
- # convenience : try to locate first based on type+pointer
- # if so, the record was created already even if e.g. its hrn has changed meanwhile
- # otherwise we try by type+hrn (is this truly useful ?)
- def locate (self, type, hrn=None, pointer=-1):
- if pointer!=-1:
- attempt = self.locate_by_type_pointer (type, pointer)
- if attempt : return attempt
- if hrn is not None:
- attempt = self.locate_by_type_hrn (type, hrn,)
- if attempt : return attempt
- return None
+ # a convenience/helper function to see if a record is already known
+ # a former, broken, attempt (in 2.1-9) had been made
+ # to try and use 'pointer' as a first, most significant attempt
+ # the idea being to preserve stuff as much as possible, and thus
+ # to avoid creating a new gid in the case of a simple hrn rename
+ # however this of course doesn't work as the gid depends on the hrn...
+ #def locate (self, type, hrn=None, pointer=-1):
+ # if pointer!=-1:
+ # attempt = self.locate_by_type_pointer (type, pointer)
+ # if attempt : return attempt
+ # if hrn is not None:
+ # attempt = self.locate_by_type_hrn (type, hrn,)
+ # if attempt : return attempt
+ # return None
# this makes the run method a bit abtruse - out of the way
def create_special_vini_record (self, interface_hrn):
# 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'])
+ ['person_id', 'email', 'key_ids', 'site_ids', 'role_ids'])
# create a hash of persons by person_id
persons_by_id = dict ( [ ( person['person_id'], person) for person in persons ] )
# Get all plc public keys
site_hrn = _get_site_hrn(interface_hrn, site)
# 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 ('authority', site_hrn, site['site_id'])
+ site_record=self.locate_by_type_hrn ('authority', site_hrn)
if not site_record:
try:
urn = hrn_to_urn(site_hrn, 'authority')
continue
site_auth = get_authority(site_hrn)
site_name = site['login_base']
- hrn = hostname_to_hrn(site_auth, site_name, node['hostname'])
+ node_hrn = hostname_to_hrn(site_auth, site_name, node['hostname'])
# xxx this sounds suspicious
- if len(hrn) > 64: hrn = hrn[:64]
- node_record = self.locate ( 'node', hrn , node['node_id'] )
+ if len(node_hrn) > 64: node_hrn = node_hrn[:64]
+ node_record = self.locate_by_type_hrn ( 'node', node_hrn )
if not node_record:
try:
pkey = Keypair(create=True)
- urn = hrn_to_urn(hrn, 'node')
+ urn = hrn_to_urn(node_hrn, 'node')
node_gid = self.auth_hierarchy.create_gid(urn, create_uuid(), pkey)
- node_record = RegNode (hrn=hrn, gid=node_gid,
+ node_record = RegNode (hrn=node_hrn, gid=node_gid,
pointer =node['node_id'],
- authority=get_authority(hrn))
+ authority=get_authority(node_hrn))
node_record.just_created()
dbsession.add(node_record)
dbsession.commit()
pass
node_record.stale=False
+ site_pis=[]
# import persons
for person_id in site['person_ids']:
try:
if len(person_hrn) > 64: person_hrn = person_hrn[:64]
person_urn = hrn_to_urn(person_hrn, 'user')
- user_record = self.locate ( 'user', person_hrn, person['person_id'])
+ user_record = self.locate_by_type_hrn ( 'user', person_hrn)
# return a tuple pubkey (a plc key object) and pkey (a Keypair object)
def init_person_key (person, plc_keys):
user_record.email = person['email']
dbsession.commit()
user_record.stale=False
+ # accumulate PIs - PLCAPI has a limitation that when someone has PI role
+ # this is valid for all sites she is in..
+ # PI is coded with role_id==20
+ if 20 in person['role_ids']:
+ site_pis.append (user_record)
except:
self.logger.log_exc("PlImporter: failed to import person %d %s"%(person['person_id'],person['email']))
+ # maintain the list of PIs for a given site
+ site_record.reg_pis = site_pis
+
# import slices
for slice_id in site['slice_ids']:
try:
except:
self.logger.warning ("PlImporter: cannot locate slice_id %s - ignored"%slice_id)
slice_hrn = slicename_to_hrn(interface_hrn, slice['name'])
- slice_record = self.locate ('slice', slice_hrn, slice['slice_id'])
+ slice_record = self.locate_by_type_hrn ('slice', slice_hrn)
if not slice_record:
try:
pkey = Keypair(create=True)