Forum Discussion
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
- Brad_Parker
Cirrus
Just use the pool command rather than the node command in conjunction with your nexthop.
- andrew_C1
Nimbostratus
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
- andrew_C1
Nimbostratus
awesome thax for that, i'll give it a bash
edit: tested, worked exactly as desired
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
