liquid_feedback_frontend
annotate env/ldap/get_hosts.lua @ 1152:851d4710452f
Removed usage of deprecated function load_chunk
author | bsw |
---|---|
date | Sun Mar 22 22:31:47 2015 +0100 (2015-03-22) |
parents | 58f48a8a202a |
children |
rev | line source |
---|---|
bsw@1071 | 1 -- generate a ready-to-use list of the configures LDAP servers |
bsw@1071 | 2 -- -------------------------------------------------------------------------- |
bsw@1071 | 3 -- result is in order of preference, including a round robin style random |
bsw@1071 | 4 -- selection of the preference of hosts with the same preference |
bsw@1071 | 5 -- |
bsw@1071 | 6 -- returns: |
bsw@1071 | 7 -- hostlist: flattened list of LDAP servers in order of preference |
bsw@1071 | 8 |
bsw@1071 | 9 function ldap.get_hosts() |
bsw@1071 | 10 |
bsw@1071 | 11 math.randomseed(os.time()) |
bsw@1071 | 12 |
bsw@1071 | 13 local hostlist = {} |
bsw@1071 | 14 |
bsw@1071 | 15 -- iterate through all entries on base level |
bsw@1071 | 16 for i, host in ipairs (config.ldap.hosts) do |
bsw@1071 | 17 |
bsw@1071 | 18 -- a single host entry |
bsw@1071 | 19 if host.uri then |
bsw@1071 | 20 hostlist[#hostlist+1] = host |
bsw@1071 | 21 |
bsw@1071 | 22 -- or a list of host entries |
bsw@1071 | 23 else |
bsw@1071 | 24 local subhostlist = {} |
bsw@1071 | 25 |
bsw@1071 | 26 -- sort list of host entries by random |
bsw@1071 | 27 for j, subhost in ipairs(host) do |
bsw@1071 | 28 subhost.priority = math.random() |
bsw@1071 | 29 subhostlist[#subhostlist+1] = subhost |
bsw@1071 | 30 end |
bsw@1071 | 31 table.sort(subhostlist, function (a,b) |
bsw@1071 | 32 return a.priority < b.priority |
bsw@1071 | 33 end) |
bsw@1071 | 34 |
bsw@1071 | 35 -- and add them to the main list |
bsw@1071 | 36 for i, subhost in ipairs(subhostlist) do |
bsw@1071 | 37 hostlist[#hostlist+1] = subhost |
bsw@1071 | 38 end |
bsw@1071 | 39 |
bsw@1071 | 40 end |
bsw@1071 | 41 |
bsw@1071 | 42 end |
bsw@1071 | 43 |
bsw@1071 | 44 return hostlist |
bsw@1071 | 45 |
bsw@1071 | 46 end |