Forum Discussion
Hank_Stallings
Nimbostratus
Jul 29, 2013Set Manual Cookie Peristence
I’m trying to implement an iRule from wiki article at:
https://devcentral.f5.com/wiki/irul...tence.ashx
I am pretty new at iRules and I’m missing something, so I apologize in advance for my...
Kevin_Stewart
Employee
Jul 30, 2013Here's a minor modification of the above using a dynamically created list on CLIENT_ACCEPTED:
when RULE_INIT {
set static::cookie_name "my_node_forced"
}
when CLIENT_ACCEPTED {
create simple pool member list
set my_nodes [members -list local-pool]
}
when HTTP_REQUEST {
Get node id from URL ending in ?node=server1, ?node=server2, etc.
set node_forced [findstr [HTTP::query] "node=" 5]
Or from previous cookie
set has_cookie [HTTP::cookie exists $static::cookie_name]
If node_forced (from query) isn't there but cookie exists - set node_forced = cookie value
if { $node_forced eq "" and $has_cookie } {
set node_forced [HTTP::cookie value $static::cookie_name]
}
If node_forced (from query) is there but cookie is not - set cookie flag
if { $node_forced ne "" and !$has_cookie } {
set do_cookie 1
}
Map node id to IP and port found in a class
if { $node_forced ne "" } {
set node_data [lindex $my_nodes $node_forced]
if { $node_data ne "" } {
set node_ip [getfield $node_data " " 1]
set node_port [getfield $node_data " " 2]
pool local-pool member $node_ip $node_port
}
}
}
when HTTP_RESPONSE {
if { [info exists do_cookie] } {
unset do_cookie
Add a cookie to continue forcing node assignment
HTTP::cookie insert name $static::cookie_name value $node_forced path "/"
}
}
Essentially the same as before, but this time a list is created dynamically of all of the pool members (set my_nodes [members -list local-pool]). Use set my_nodes [active_members -list local-pool] to get a list of only the available nodes. Then later just read that list entry to get the desired node (set node_data [lindex $my_nodes $node_forced]).
An alternative method would be to modify the data group via shell script and TMSH commands on some specified interval. Create an external monitor that polls the pool members, rewrites the data group, then updates it in the config. Add this monitor to a "phantom pool" - a pool not tied to a virtual server. This method allows you to create a scheduled job that is backed up as part of the config.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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