3 # Bootstraps the PLC database with a default administrator account and
6 # Mark Huang <mlhuang@cs.princeton.edu>
7 # Copyright (C) 2006 The Trustees of Princeton University
13 (plcapi, moreopts, argv) = plcapilib.plcapi(globals())
14 from plc_config import PLCConfiguration
18 cfg = PLCConfiguration()
20 variables = cfg.variables()
22 # Load variables into dictionaries
23 (category, variablelist) = variables['plc']
24 plc = dict(zip(variablelist.keys(),
25 [variable['value'] for variable in variablelist.values()]))
27 (category, variablelist) = variables['plc_www']
28 plc_www = dict(zip(variablelist.keys(),
29 [variable['value'] for variable in variablelist.values()]))
31 (category, variablelist) = variables['plc_api']
32 plc_api = dict(zip(variablelist.keys(),
33 [variable['value'] for variable in variablelist.values()]))
35 # Create/update the default administrator account (should be
37 admin = { 'person_id': 2,
38 'first_name': "Default",
39 'last_name': "Administrator",
40 'email': plc['root_user'],
41 'password': plc['root_password'] }
42 persons = AdmGetPersons([admin['person_id']])
44 person_id = AdmAddPerson(admin['first_name'], admin['last_name'], admin)
45 if person_id != admin['person_id']:
46 # Huh? Someone deleted the account manually from the database.
47 AdmDeletePerson(person_id)
48 raise Exception, "Someone deleted the \"%s %s\" account from the database!" % \
49 (admin['first_name'], admin['last_name'])
50 AdmSetPersonEnabled(person_id, True)
52 person_id = persons[0]['person_id']
53 AdmUpdatePerson(person_id, admin)
55 # Create/update the default site (should be site_id 0)
56 if plc_www['port'] == '80':
57 url = "http://" + plc_www['host'] + "/"
58 elif plc_www['port'] == '443':
59 url = "https://" + plc_www['host'] + "/"
61 url = "http://" + plc_www['host'] + ":" + plc_www['port'] + "/"
62 site = { 'site_id': 1,
63 'name': plc['name'] + " Central",
64 'abbreviated_name': plc['name'],
65 'login_base': plc['slice_prefix'],
70 sites = AdmGetSites([site['site_id']])
72 site_id = AdmAddSite(site['name'], site['abbreviated_name'], site['login_base'], site)
73 if site_id != site['site_id']:
74 AdmDeleteSite(site_id)
75 raise Exception, "Someone deleted the \"%s\" site from the database!" % \
78 site_id = sites[0]['site_id']
79 # XXX login_base cannot be updated
80 del site['login_base']
81 AdmUpdateSite(site_id, site)
83 # The default administrator account must be associated with a site
85 AdmAddPersonToSite(admin['person_id'], site['site_id'])
86 AdmSetPersonPrimarySite(admin['person_id'], site['site_id'])
88 # Grant admin and PI roles to the default administrator account
89 AdmGrantRoleToPerson(admin['person_id'], 10)
90 AdmGrantRoleToPerson(admin['person_id'], 20)
92 # XXX Setup default slice attributes and initscripts (copy from PLC)
94 # XXX Setup PlanetLabConf entries (copy from PLC)
96 if __name__ == '__main__':