Commit bd53a1a0 authored by Zenon Mousmoulas's avatar Zenon Mousmoulas Committed by GitHub

Merge pull request #33 from zmousm/fix/master/servdata_deduplist

Servdata consumer templates: server list handling fixes
parents 09445189 ce84d060
......@@ -17,6 +17,9 @@ def wildcard_realm_least_precedence(a, b):
return 1
else:
return 0
def deduplicated_list(seq):
seen = set()
return [x for x in seq if not (x in seen or seen.add(x))]
%>\
% for inst in insts:
% if inst['type'] in (1, 3) and 'realms' in inst:
......@@ -24,13 +27,15 @@ def wildcard_realm_least_precedence(a, b):
<%doc>
The following one-liner does the equivalent of:
inst_servers = set()
inst_servers = []
for r in inst['realms']:
if 'proxy_to' in inst['realms'][r]:
inst_servers.update(inst['realms'][r]['proxy_to'])
inst_servers.append(inst['realms'][r]['proxy_to'])
# deduplicate like set, but preserve order
inst_servers = deduplicated_list(inst_servers)
for srv in inst_servers:
</%doc>\
% for srv in set([s for r in inst['realms'] for s in inst['realms'][r]['proxy_to'] if 'proxy_to' in inst['realms'][r]]):
% for srv in deduplicated_list([s for r in inst['realms'] for s in inst['realms'][r]['proxy_to'] if 'proxy_to' in inst['realms'][r]]):
% if 'seen' in servers[srv]:
# server ${srv} defined previously
% else:
......@@ -59,10 +64,14 @@ servers[srv]['seen'] = True
<%
realm_servers = {}
for t in ['auth', 'acct', 'auth+acct']:
realm_servers[t] = set([s for s in inst['realms'][realm]['proxy_to']
if servers[s]['rad_pkt_type'] == t])
realm_servers[t] = deduplicated_list([s for s in inst['realms'][realm]['proxy_to']
if servers[s]['rad_pkt_type'] == t])
if len(realm_servers['auth+acct']) != len(inst['realms'][realm]['proxy_to']):
realm_servers['auth'] += realm_servers['auth+acct']
realm_servers['acct'] += realm_servers['auth+acct']
realm_servers['auth+acct'] = []
%>\
% if len(realm_servers['auth+acct']) == len(inst['realms'][realm]['proxy_to']):
% if len(realm_servers['auth+acct']) > 0:
home_server_pool ${realm | realm_disarm} {
type = fail-over
% for srv in realm_servers['auth+acct']:
......@@ -81,16 +90,15 @@ home_server_pool ${realm | realm_disarm}_auth {
% if len(realm_servers['acct']) > 0:
home_server_pool ${realm | realm_disarm}_acct {
type = fail-over
% for srv in realm_servers['auth']:
% for srv in realm_servers['acct']:
home_server = ${srv}
% endfor
}
% endif
% endif
% if len(realm_servers['auth+acct']) == len(inst['realms'][realm]['proxy_to']) \
or len(realm_servers['auth']) > 0:
% if len(realm_servers['auth+acct']) > 0 or len(realm_servers['auth']) > 0:
realm ${realm | realm_regex} {
% if len(realm_servers['auth+acct']) == len(inst['realms'][realm]['proxy_to']):
% if len(realm_servers['auth+acct']) > 0:
pool = ${realm | realm_disarm}
% else:
auth_pool = ${realm | realm_disarm}_auth
......
......@@ -17,6 +17,9 @@ def wildcard_realm_least_precedence(a, b):
return 1
else:
return 0
def deduplicated_list(seq):
seen = set()
return [x for x in seq if not (x in seen or seen.add(x))]
%>\
<%
for inst in insts:
......@@ -62,13 +65,15 @@ clients[client]['seen'] = True
<%doc>
The following one-liner does the equivalent of:
inst_servers = set()
inst_servers = []
for r in inst['realms']:
if 'proxy_to' in inst['realms'][r]:
inst_servers.update(inst['realms'][r]['proxy_to'])
inst_servers.append(inst['realms'][r]['proxy_to'])
# deduplicate like set, but preserve order
inst_servers = deduplicated_list(inst_servers)
for srv in inst_servers:
</%doc>\
% for srv in set([s for r in inst['realms'] for s in inst['realms'][r]['proxy_to'] if 'proxy_to' in inst['realms'][r]]):
% for srv in deduplicated_list([s for r in inst['realms'] for s in inst['realms'][r]['proxy_to'] if 'proxy_to' in inst['realms'][r]]):
% if 'seen' in servers[srv]:
# server ${srv} defined previously
% else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment