import sys
import tempfile
+from sfa.util.record import *
+from sfa.util.genitable import GeniTable
+from sfa.util.misc import *
+from sfa.util.config import Config
+from sfa.util.report import trace, error
+
from sfa.trust.certificate import convert_public_key, Keypair
from sfa.trust.trustedroot import *
-
from sfa.trust.hierarchy import *
-from sfa.util.record import *
-from sfa.util.genitable import *
-from sfa.util.misc import *
-from sfa.util.config import *
+from sfa.trust.gid import create_uuid
+
+config = Config()
# get PL account settings from config module
-pl_auth = get_pl_auth()
+plc_auth = config.get_plc_auth()
+shell = None
def connect_shell():
- global pl_auth, shell
-
- # get PL account settings from config module
- pl_auth = get_pl_auth()
+ global plc_auth
# connect to planetlab
- if "Url" in pl_auth:
- from sfa.plc import remoteshell
- shell = remoteshell.RemoteShell()
+ if "Url" in plc_auth:
+ from sfa.plc.remoteshell import RemoteShell
+ shell = RemoteShell()
else:
import PLC.Shell
shell = PLC.Shell.Shell(globals = globals())
-
return shell
# connect to planetlab
#root_auth = "planetlab"
#level1_auth = "planetlab.us"
-config = Config()
root_auth = config.SFA_REGISTRY_ROOT_AUTH
level1_auth = config.SFA_REGISTRY_LEVEL1_AUTH
# into this authority yet.
if not table.exists():
- report.trace("Import: creating table for authority " + auth_name)
+ trace("Import: creating table for authority " + auth_name)
table.create()
return table
if len(hrn) > 64:
hrn = hrn[:64]
- report.trace("Import: importing person " + hrn)
+ trace("Import: importing person " + hrn)
table = get_auth_table(parent_hrn)
# get the user's private key from the SSH keys they have uploaded
# to planetlab
- keys = shell.GetKeys(pl_auth, key_ids)
+ keys = shell.GetKeys(plc_auth, key_ids)
key = keys[0]['key']
pkey =convert_public_key(key)
else:
# the user has no keys
- report.trace(" person " + hrn + " does not have a PL public key")
+ trace(" person " + hrn + " does not have a PL public key")
# if a key is unavailable, then we still need to put something in the
# user's GID. So make one up.
person_gid = AuthHierarchy.create_gid(hrn, create_uuid(), pkey)
person_record = table.resolve("user", hrn)
if not person_record:
- report.trace(" inserting user record for " + hrn)
+ trace(" inserting user record for " + hrn)
person_record = GeniRecord(hrn=hrn, gid=person_gid, type="user", pointer=person['person_id'])
table.insert(person_record)
else:
- report.trace(" updating user record for " + hrn)
+ trace(" updating user record for " + hrn)
person_record = GeniRecord(hrn=hrn, gid=person_gid, type="user", pointer=person['person_id'])
table.update(person_record)
slicename = cleanup_string(slicename)
if not slicename:
- report.error("Import_Slice: failed to parse slice name " + slice['name'])
+ error("Import_Slice: failed to parse slice name " + slice['name'])
return
hrn = parent_hrn + "." + slicename
- report.trace("Import: importing slice " + hrn)
+ trace("Import: importing slice " + hrn)
table = get_auth_table(parent_hrn)
pkey = Keypair(create=True)
slice_gid = AuthHierarchy.create_gid(hrn, create_uuid(), pkey)
slice_record = GeniRecord(hrn=hrn, gid=slice_gid, type="slice", pointer=slice['slice_id'])
- report.trace(" inserting slice record for " + hrn)
+ trace(" inserting slice record for " + hrn)
table.insert(slice_record)
def import_node(parent_hrn, node):
nodename = cleanup_string(nodename)
if not nodename:
- report.error("Import_node: failed to parse node name " + node['hostname'])
+ error("Import_node: failed to parse node name " + node['hostname'])
return
hrn = parent_hrn + "." + nodename
if len(hrn) > 64:
hrn = hrn[:64]
- report.trace("Import: importing node " + hrn)
+ trace("Import: importing node " + hrn)
table = get_auth_table(parent_hrn)
pkey = Keypair(create=True)
node_gid = AuthHierarchy.create_gid(hrn, create_uuid(), pkey)
node_record = GeniRecord(hrn=hrn, gid=node_gid, type="node", pointer=node['node_id'])
- report.trace(" inserting node record for " + hrn)
+ trace(" inserting node record for " + hrn)
table.insert(node_record)
def import_site(parent_hrn, site):
hrn = ".".join([parent_hrn, "internet2", sitename])
sitename = sitename.replace("nlr", "")
- report.trace("Import_Site: importing site " + hrn)
+ trace("Import_Site: importing site " + hrn)
# create the authority
if not AuthHierarchy.auth_exists(hrn):
auth_record = table.resolve("authority", hrn)
if not auth_record:
auth_record = GeniRecord(hrn=hrn, gid=auth_info.get_gid_object(), type="authority", pointer=site['site_id'])
- report.trace(" inserting authority record for " + hrn)
+ trace(" inserting authority record for " + hrn)
table.insert(auth_record)
if 'person_ids' in site:
for person_id in site['person_ids']:
- persons = shell.GetPersons(pl_auth, [person_id])
+ persons = shell.GetPersons(plc_auth, [person_id])
if persons:
try:
import_person(hrn, persons[0])
except Exception, e:
- report.trace("Failed to import: %s (%s)" % (persons[0], e))
+ trace("Failed to import: %s (%s)" % (persons[0], e))
if 'slice_ids' in site:
for slice_id in site['slice_ids']:
- slices = shell.GetSlices(pl_auth, [slice_id])
+ slices = shell.GetSlices(plc_auth, [slice_id])
if slices:
try:
import_slice(hrn, slices[0])
except Exception, e:
- report.trace("Failed to import: %s (%s)" % (slices[0], e))
+ trace("Failed to import: %s (%s)" % (slices[0], e))
if 'node_ids' in site:
for node_id in site['node_ids']:
- nodes = shell.GetNodes(pl_auth, [node_id])
+ nodes = shell.GetNodes(plc_auth, [node_id])
if nodes:
try:
import_node(hrn, nodes[0])
except Exception, e:
- report.trace("Failed to import: %s (%s)" % (nodes[0], e))
+ trace("Failed to import: %s (%s)" % (nodes[0], e))
def create_top_level_auth_records(hrn):
parent_hrn = get_authority(hrn)
auth_record = table.resolve("authority", hrn)
if not auth_record:
auth_record = GeniRecord(hrn=hrn, gid=auth_info.get_gid_object(), type="authority", pointer=-1)
- report.trace(" inserting authority record for " + hrn)
+ trace(" inserting authority record for " + hrn)
table.insert(auth_record)
def main():
root = AuthHierarchy.get_auth_info(root_auth)
TrustedRoots.add_gid(root.get_gid_object())
- connect_shell()
-
- sites = shell.GetSites(pl_auth, {'peer_id': None})
+ sites = shell.GetSites(plc_auth, {'peer_id': None})
# create a fake internet2 site first
i2site = {'name': 'Internet2', 'abbreviated_name': 'I2',
'login_base': 'internet2', 'site_id': -1}