[dnsdist] Using server names for a custom serverPolicy

Remi Gacogne remi.gacogne at powerdns.com
Tue Mar 28 13:10:01 UTC 2017


Hi,

On 03/27/2017 12:37 PM, Thib D wrote:
> I am currently working on a custom serverPolicy function.
> 
> Here is a sample of the serverPolicy I made :
> 
>         if not (servers[1]:isUp() and servers[2]:isUp()) then
>                 servers[4].order = 1
>         else if not (servers[4].order == 2) then
>                 servers[4].order = 2
>         end
>         end
> 
> This is working as expected, but I want to use a server name instead of
> using the table servers[].
> The sample also works using the getServer(n) method instead of
> servers[n]. Obviously, It is better to call servers by their name
> (because it is not going to change) instead of a number that can change
> if we add more servers.

Policy functions get a list of of backend candidates based on the pool
that has been selected, so except if you have a very static
configuration I don't advise the use of names there.
If you really want to do so, I'd suggest constructing a Lua table using
the backend name as key, by iterating through the list passed to your
function and using the getName() method on each backend.

Best regards,

-- 
Remi Gacogne
PowerDNS.COM BV - https://www.powerdns.com/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://mailman.powerdns.com/pipermail/dnsdist/attachments/20170328/877bc06e/attachment.sig>


More information about the dnsdist mailing list