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'] + "/"
15 site = { 'site_id': 1,
16 'name': plc['name'] + " Central",
17 'abbreviated_name': plc['name'],
18 'login_base': plc['slice_prefix'],
23 sites = GetSites([site['site_id']])
25 site_id = AddSite(site['name'], site['abbreviated_name'], site['login_base'], site)
26 if site_id != site['site_id']:
28 raise Exception, "Someone deleted the \"%s\" site from the database!" % \
32 # Must call UpdateSite() even after AddSite() to update max_slices
33 site_id = sites[0]['site_id']
34 UpdateSite(site_id, site)
36 # The default administrator account must be associated with a site
37 # in order to login - see 001-admin_user
38 AddPersonToSite(the_admin_id, site['site_id'])
39 SetPersonPrimarySite(the_admin_id, site['site_id'])
41 # Grant admin and PI roles to the default administrator account
42 AddRoleToPerson(10, the_admin_id)
43 AddRoleToPerson(20, the_admin_id)
45 # Associate root ssh key with the default administrator
46 keyfile=plc['root_ssh_key_pub']
47 person = GetPersons(the_admin_id)[0]
48 keys = GetKeys(person['key_ids'])
49 if os.path.exists(keyfile):
50 sshkeyfp = file(keyfile,"r")
51 sshkey = sshkeyfp.read()
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