X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=db-config.d%2F002-system_site;h=698ea59832cbde5968c8647a13101a9993109f4c;hb=2fb2ab94189643bedabcef1b585671da5a01832e;hp=12e00a76a6ee04e171e0a889de218caf0fce2979;hpb=123bd2f54d1cf801f08b74e5e1db559ed40240d5;p=plcapi.git diff --git a/db-config.d/002-system_site b/db-config.d/002-system_site index 12e00a7..698ea59 100644 --- a/db-config.d/002-system_site +++ b/db-config.d/002-system_site @@ -1,8 +1,8 @@ # -*-python-*- -#################### +#################### # Create/update and populate the default site (should be site_id 1) -### plc_www holds the contents of the PLC_WWW configuration category +# plc_www holds the contents of the PLC_WWW configuration category if plc_www['port'] == '80': url = "http://" + plc_www['host'] + "/" elif plc_www['port'] == '443': @@ -12,21 +12,22 @@ else: SetMyPLCURL(url) -site = { 'site_id': 1, - 'name': plc['name'] + " Central", - 'abbreviated_name': plc['name'], - 'login_base': plc['slice_prefix'], - 'is_public': False, - 'url': url, - 'max_slices': 100 } +site = {'site_id': 1, + 'name': plc['name'] + " Central", + 'abbreviated_name': plc['name'], + 'login_base': plc['slice_prefix'], + 'is_public': False, + 'url': url, + 'max_slices': 100} sites = GetSites([site['site_id']]) if not sites: - site_id = AddSite(site['name'], site['abbreviated_name'], site['login_base'], site) + site_id = AddSite( + site['name'], site['abbreviated_name'], site['login_base'], site) if site_id != site['site_id']: DeleteSite(site_id) - raise Exception, "Someone deleted the \"%s\" site from the database!" % \ - site['name'] + raise Exception("Someone deleted the \"%s\" site from the database!" % + site['name']) sites = [site] # Must call UpdateSite() even after AddSite() to update max_slices @@ -34,34 +35,33 @@ site_id = sites[0]['site_id'] UpdateSite(site_id, site) # The default administrator account must be associated with a site -# in order to login. -AddPersonToSite(admin['person_id'], site['site_id']) -SetPersonPrimarySite(admin['person_id'], site['site_id']) +# in order to login - see 001-admin_user +AddPersonToSite(the_admin_id, site['site_id']) +SetPersonPrimarySite(the_admin_id, site['site_id']) # Grant admin and PI roles to the default administrator account -AddRoleToPerson(10, admin['person_id']) -AddRoleToPerson(20, admin['person_id']) +AddRoleToPerson(10, the_admin_id) +AddRoleToPerson(20, the_admin_id) # Associate root ssh key with the default administrator -keyfile=plc['root_ssh_key_pub'] -person = GetPersons(admin['person_id'])[0] +keyfile = plc['root_ssh_key_pub'] +person = GetPersons(the_admin_id)[0] keys = GetKeys(person['key_ids']) if os.path.exists(keyfile): - sshkeyfp = file(keyfile,"r") - sshkey = sshkeyfp.read() - sshkeyfp.close() + with open(keyfile) as feed: + sshkey = feed.read() - found=False + found = False for key in keys: - if key['key_type']=='ssh': + if key['key_type'] == 'ssh': if key['key'] == sshkey: - found=True + found = True else: # should we delete other keys? pass if not found: - key_id = AddPersonKey(admin['person_id'],{'key_type':'ssh','key':sshkey}) + key_id = AddPersonKey(the_admin_id, {'key_type': 'ssh', 'key': sshkey}) else: - if len(keys)==0: - print "WARNING: default administrator does not have an ssh key" - print "and the default ssh root pub key (%s) file does not exist." % keyfile + if not keys: + print("WARNING: default administrator does not have an ssh key") + print("and the default ssh root pub key (%s) file does not exist." % keyfile)