5 # Create/update and populate the default site (should be site_id 1)
7 ### plc_www holds the contents of the PLC_WWW configuration category
8 if plc_www['port'] == '80':
9 url = "http://" + plc_www['host'] + "/"
10 elif plc_www['port'] == '443':
11 url = "https://" + plc_www['host'] + "/"
13 url = "http://" + plc_www['host'] + ":" + plc_www['port'] + "/"
17 site = { 'site_id': 1,
18 'name': plc['name'] + " Central",
19 'abbreviated_name': plc['name'],
20 'login_base': plc['slice_prefix'],
25 sites = GetSites([site['site_id']])
27 site_id = AddSite(site['name'], site['abbreviated_name'], site['login_base'], site)
28 if site_id != site['site_id']:
30 raise Exception, "Someone deleted the \"%s\" site from the database!" % \
34 # Must call UpdateSite() even after AddSite() to update max_slices
35 site_id = sites[0]['site_id']
36 UpdateSite(site_id, site)
38 # The default administrator account must be associated with a site
40 AddPersonToSite(admin['person_id'], site['site_id'])
41 SetPersonPrimarySite(admin['person_id'], site['site_id'])
43 # Grant admin and PI roles to the default administrator account
44 AddRoleToPerson(10, admin['person_id'])
45 AddRoleToPerson(20, admin['person_id'])
47 # Associate root ssh key with the default administrator
48 keyfile=plc['root_ssh_key_pub']
49 person = GetPersons(admin['person_id'])[0]
50 keys = GetKeys(person['key_ids'])
51 if os.path.exists(keyfile):
52 sshkeyfp = file(keyfile,"r")
53 sshkey = sshkeyfp.read()
58 if key['key_type']=='ssh':
59 if key['key'] == sshkey:
62 # should we delete other keys?
65 key_id = AddPersonKey(admin['person_id'],{'key_type':'ssh','key':sshkey})
68 print "WARNING: default administrator does not have an ssh key"
69 print "and the default ssh root pub key (%s) file does not exist." % keyfile