7 # Import PLC records into the Geni database. It is indended that this tool be
8 # run once to create Geni records that reflect the current state of the
11 # The import tool assumes that the existing PLC hierarchy should all be part
12 # of "planetlab.us" (see the root_auth and level1_auth variables below).
14 # Public keys are extracted from the users' SSH keys automatically and used to
15 # create GIDs. This is relatively experimental as a custom tool had to be
16 # written to perform conversion from SSH to OpenSSL format. It only supports
17 # RSA keys at this time, not DSA keys.
24 from sfa.util.record import *
25 from sfa.util.genitable import GeniTable
26 from sfa.util.misc import *
27 from sfa.util.config import Config
28 from sfa.util.report import trace, error
30 from sfa.trust.certificate import convert_public_key, Keypair
31 from sfa.trust.trustedroot import *
32 from sfa.trust.hierarchy import *
33 from sfa.trust.gid import create_uuid
34 from sfa.plc.sfaImport import *
38 def process_options():
41 (options, args) = getopt.getopt(sys.argv[1:], '', [])
49 root_auth = config.SFA_REGISTRY_ROOT_AUTH
50 level1_auth = config.SFA_REGISTRY_LEVEL1_AUTH
51 sfaImporter = sfaImport()
52 shell = sfaImporter.shell
53 plc_auth = sfaImporter.plc_auth
54 AuthHierarchy = sfaImporter.AuthHierarchy
55 TrustedRoots = sfaImporter.TrustedRoots
57 if not table.exists():
60 if not level1_auth or level1_auth in ['']:
63 print "Import: creating top level authorities"
65 sfaImporter.create_top_level_auth_records(root_auth)
66 import_auth = root_auth
68 if not AuthHierarchy.auth_exists(level1_auth):
69 AuthHierarchy.create_auth(level1_auth)
70 sfaImporter.create_top_level_auth_records(level1_auth)
71 import_auth = level1_auth
73 print "Import: adding", import_auth, "to trusted list"
74 authority = AuthHierarchy.get_auth_info(import_auth)
75 TrustedRoots.add_gid(authority.get_gid_object())
77 if ".vini" in import_auth and import_auth.endswith('vini'):
78 # create a fake internet2 site first
79 i2site = {'name': 'Internet2', 'abbreviated_name': 'I2',
80 'login_base': 'internet2', 'site_id': -1}
81 sfaImporter.import_site(import_auth, i2site)
83 # create dict of all existing sfa records
86 results = table.find()
87 for result in results:
88 existing_records[(result['hrn'], result['type'])] = result
89 existing_hrns.append(result['hrn'])
92 sites = shell.GetSites(plc_auth)
95 persons = shell.GetPersons(plc_auth, {}, ['person_id', 'email', 'key_ids'])
97 for person in persons:
98 persons_dict[person['person_id']] = person
101 nodes = shell.GetNodes(plc_auth, {}, ['node_id', 'hostname'])
104 nodes_dict[node['node_id']] = node
107 slices = shell.GetSlices(plc_auth, {}, ['slice_id', 'name'])
110 slices_dict[slice['slice_id']] = slice
114 site_hrn = import_auth + "." + site['login_base']
115 # import if hrn is not in list of existing hrns or if the hrn exists
116 # but its not a site record
117 if site_hrn not in existing_hrns or \
118 (site_hrn, 'authority') not in existing_records:
119 sfaImporter.import_site(import_auth, site)
122 # import node records
123 for node_id in site['node_ids']:
124 if node_id not in nodes_dict:
126 node = nodes_dict[node_id]
127 hrn = hostname_to_hrn(import_auth, site['login_base'], node['hostname'])
128 if hrn not in existing_hrns or \
129 (hrn, 'node') not in existing_records:
130 sfaImporter.import_node(site_hrn, node)
133 for slice_id in site['slice_ids']:
134 if slice_id not in slices_dict:
136 slice = slices_dict[slice_id]
137 hrn = slicename_to_hrn(import_auth, slice['name'])
138 if hrn not in existing_hrns or \
139 (hrn, 'slice') not in existing_records:
140 sfaImporter.import_slice(site_hrn, slice)
143 for person_id in site['person_ids']:
144 if person_id not in persons_dict:
146 person = persons_dict[person_id]
147 hrn = email_to_hrn(site_hrn, person['email'])
148 if hrn not in existing_hrns or \
149 (hrn, 'user') not in existing_records:
150 sfaImporter.import_person(site_hrn, person)
152 if __name__ == "__main__":