import sys
from sfa.util.config import Config
-from sfa.util.xrn import Xrn, get_leaf, get_authority
+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.storage.table import SfaTable
-
-from sfa.importer.sfaImport import sfaImport
+from sfa.storage.record import SfaRecord
+from sfa.trust.gid import create_uuid
+from sfa.trust.certificate import convert_public_key, Keypair
+from sfa.importer.sfaImport import sfaImport, _cleanup_string
+from sfa.util.sfalogging import logger
def process_options():
# but its not a site record
if site_hrn not in existing_hrns or \
(site_hrn, 'authority') not in existing_records:
- sfaImporter.import_site(site_hrn, site)
+ logger.info("Import: site %s " % site_hrn)
+ urn = hrn_to_urn(site_hrn, 'authority')
+ if not sfaImporter.AuthHierarchy.auth_exists(urn):
+ sfaImporter.AuthHierarchy.create_auth(urn)
+ auth_info = sfaImporter.AuthHierarchy.get_auth_info(urn)
+ auth_record = SfaRecord(hrn=site_hrn, gid=auth_info.get_gid_object(), type="authority", pointer=site['site_id'])
+ auth_record.sync(verbose=True)
# import node records
for node_id in site['node_ids']:
site_auth = get_authority(site_hrn)
site_name = get_leaf(site_hrn)
hrn = hostname_to_hrn(site_auth, site_name, node['hostname'])
+ if len(hrn) > 64:
+ hrn = hrn[:64]
if hrn not in existing_hrns or \
(hrn, 'node') not in existing_records:
- sfaImporter.import_node(hrn, node)
+ pkey = Keypair(create=True)
+ urn = hrn_to_urn(hrn, 'node')
+ node_gid = sfaImporter.AuthHierarchy.create_gid(urn, create_uuid(), pkey)
+ node_record = SfaRecord(hrn=hrn, gid=node_gid, type="node", pointer=node['node_id'], authority=get_authority(hrn))
+ node_record.sync(verbose=True)
# import slices
for slice_id in site['slice_ids']:
continue
slice = slices_dict[slice_id]
hrn = slicename_to_hrn(interface_hrn, slice['name'])
+ #slicename = slice['name'].split("_",1)[-1]
+ #slicename = _cleanup_string(slicename)
if hrn not in existing_hrns or \
(hrn, 'slice') not in existing_records:
- sfaImporter.import_slice(site_hrn, slice)
+ pkey = Keypair(create=True)
+ urn = hrn_to_urn(hrn, 'slice')
+ slice_gid = sfaImporter.AuthHierarchy.create_gid(urn, create_uuid(), pkey)
+ slice_record = SfaRecord(hrn=hrn, gid=slice_gid, type="slice", pointer=slice['slice_id'],
+ authority=get_authority(hrn))
+ slice_record.sync(verbose=True)
# import persons
for person_id in site['person_ids']:
continue
person = persons_dict[person_id]
hrn = email_to_hrn(site_hrn, person['email'])
+ if len(hrn) > 64:
+ hrn = hrn[:64]
+
+ # if user's primary key has chnaged then we need to update the
+ # users gid by forcing a update here
old_keys = []
new_keys = []
if person_id in old_person_keys:
if hrn not in existing_hrns or \
(hrn, 'user') not in existing_records or update_record:
- sfaImporter.import_person(site_hrn, person)
-
+ if 'key_ids' in person and person['key_ids']:
+ key = new_keys[0]
+ try:
+ pkey = convert_public_key(key)
+ except:
+ logger.warn('unable to convert public key for %s' % hrn)
+ pkey = Keypair(create=True)
+ else:
+ # the user has no keys. Creating a random keypair for the user's gid
+ logger.warn("Import: person %s does not have a PL public key"%hrn)
+ pkey = Keypair(create=True)
+ urn = hrn_to_urn(hrn, 'user')
+ person_gid = sfaImporter.AuthHierarchy.create_gid(urn, create_uuid(), pkey)
+ person_record = SfaRecord(hrn=hrn, gid=person_gid, type="user", \
+ pointer=person['person_id'], authority=get_authority(hrn))
+ person_record.sync(verbose=True)
# remove stale records
system_records = [interface_hrn, root_auth, interface_hrn + '.slicemanager']
if not found:
record_object = existing_records[(record_hrn, type)]
- sfaImporter.delete_record(record_hrn, type)
+ record = SfaRecord(dict=record_object)
+ record.delete()
# save pub keys
logger.info('Import: saving current pub keys')