Forum Discussion
Sake_Blok
Nimbostratus
Sep 30, 2005Dynamically selecting a class (based on poolname)
Hi,
Is it possible to dynamically select a class? I want to use one class per pool which lists a cookie per server and select that server based on the cookie. Using passive cookies is not an option since I cannot change the cookie-values on the server. Of course I can write an iRule per virtual server, but it would be nicer to have a general one that is able to select the appropriate class.
It would be something like this:
rule prefCookie-iRule {
when CLIENT_ACCEPTED {
set defpool [LB::server pool]
log local0. "defpool selected for -> $defpool"
}
when HTTP_REQUEST {
if { [HTTP::cookie exists "lbsid"] } {
set tmp [findclass [HTTP::cookie "lbsid"] ::$defpool " "]
if { $tmp ne "" } {
log local0. $tmp
node $tmp
} else {
log local0. "[HTTP::cookie "lbsid"] is not a valid cookie-value!"
pool $defpool
}
} else {
log local0. "No lbsid cookie found!"
pool $defpool
}
}
when LB_FAILED {
log local0. "LB failed, so chose a new member!"
pool $defpool
LB::reselect
}
}
The problem is that the line 'set tmp [findclass [HTTP::cookie "lbsid"] ::$defpool " "]' does not work, it looks like this line is interpreted __before__ $defpool is set. How can I solve this? I guess I need a command that has a class as output and a string as input, but is there anything capable of doing that?
Cheers, Sake
- drteeth_127330Historic F5 AccountYou also should be able to do this with the subst command which might not be as heavy weight as eval. subst performs variable substitution, so the argument is expanded twice, once by the TCL interpreter and once by subst. Something like this should work:
set tmp [findclass [HTTP::cookie "lbsid"] [subst $::$defpool] " "]
- drteeth_127330Historic F5 AccountDid you try my original suggestion?
set tmp [findclass [HTTP::cookie "lbsid"] [subst $::$defpool] " "]
- unRuleY_95363Historic F5 AccountYou need to have a $ in front of the ::.
- unRuleY_95363Historic F5 AccountBTW, you could still use subst, but like this:
set tmp [eval [subst {findclass [HTTP::cookie "lbsid"] \$::$defpool " "}]]
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects