Forum Discussion

andrew_C1's avatar
andrew_C1
Icon for Nimbostratus rankNimbostratus
Nov 30, 2015

is there a way to pick a random entry from a list

I have implemented an F5 as a double nat device where both sides have overlapping address space. As a result i have no routing configured on the F5 but use irules to set next hops etc. Because of this setup standard load balancing instantly fails (no routes). Now i can get around that pretty easy

 

when DNS_REQUEST {
set members [active_members -list $static::dns_pool]
log local5. " set destination dns server [lindex $members end]"
node [lindex $members end]
nexthop $next_vlan $next_hop
}

 

So the question is how can i pick at random a member out of $members? In perl its as simple as "my $element = $array->[ rand(@$array) ]" but i dont know TCL very well

cheers

4 Replies

  • Just use the pool command rather than the node command in conjunction with your nexthop.

     

  • hi,

     

    got around to testing and it doesn't work, i can log from the irule the node selected when using the pool command but the F5 doesn't forward the traffic ( from a tcpdump of -i 0.0 port 53).

     

    cheers

     

  • Hi Andrew,

    I don't understand what your trying to achive, but to round-robin a TCL list you may want to use...

     

    [lindex $members [expr {int(rand()*[llength $members])}]]
    

     

    BTW: A List is not comparable to an array. A List is more or less just multiple strings chained in a row and seperated by spaces. An Array is also available in TCL and is more or less a collection of independent variables stored in a hash-based container. The order of List entries is always fixed and Arrays doens't even have an order.

    Cheers, Kai

  • awesome thax for that, i'll give it a bash

     

    edit: tested, worked exactly as desired