3 # Create/update and populate the default site (should be site_id 1)
5 # plc_www holds the contents of the PLC_WWW configuration category
6 if plc_www['port'] == '80':
7 url = "http://" + plc_www['host'] + "/"
8 elif plc_www['port'] == '443':
9 url = "https://" + plc_www['host'] + "/"
11 url = "http://" + plc_www['host'] + ":" + plc_www['port'] + "/"
16 'name': plc['name'] + " Central",
17 'abbreviated_name': plc['name'],
18 'login_base': plc['slice_prefix'],
23 sites = GetSites([site['site_id']])
26 site['name'], site['abbreviated_name'], site['login_base'], site)
27 if site_id != site['site_id']:
29 raise Exception("Someone deleted the \"%s\" site from the database!" %
33 # Must call UpdateSite() even after AddSite() to update max_slices
34 site_id = sites[0]['site_id']
35 UpdateSite(site_id, site)
37 # The default administrator account must be associated with a site
38 # in order to login - see 001-admin_user
39 AddPersonToSite(the_admin_id, site['site_id'])
40 SetPersonPrimarySite(the_admin_id, site['site_id'])
42 # Grant admin and PI roles to the default administrator account
43 AddRoleToPerson(10, the_admin_id)
44 AddRoleToPerson(20, the_admin_id)
46 # Associate root ssh key with the default administrator
47 keyfile = plc['root_ssh_key_pub']
48 person = GetPersons(the_admin_id)[0]
49 keys = GetKeys(person['key_ids'])
50 if os.path.exists(keyfile):
51 with open(keyfile) as feed:
56 if key['key_type'] == 'ssh':
57 if key['key'] == sshkey:
60 # should we delete other keys?
63 key_id = AddPersonKey(the_admin_id, {'key_type': 'ssh', 'key': sshkey})
66 print("WARNING: default administrator does not have an ssh key")
67 print("and the default ssh root pub key (%s) file does not exist." % keyfile)