Forum Discussion
Robert_Landrito
Sep 30, 2009Nimbostratus
It's just a basic failover iRule. The idea is to use a designated "failover pool" for a given pool. I know I could do this with priorities but I need to snat as the "failover pool" will be a vip on an LB at an alternate datacenter. In addition to adding the snat, I inject a header to try and prevent any crazy loops between LB's. If you have any suggestions or improvements, especially regarding efficiency, do share.
when RULE_INIT {
set ::remoteDCSnatPool "remote-dc-snat"
}
when CLIENT_ACCEPTED {
set defaultPool [LB::server pool]
set failoverPool "[LB::server pool]-failover"
set failover 0
}
when HTTP_REQUEST {
if { [active_members $defaultPool] < 1 || $failover == 1 } {
if { [HTTP::header exists lb_origin] } {
log local0. "lb_origin detected, rejecting"
reject
} else {
log local0. "Failing over to $failoverPool"
set failover 1
HTTP::header insert "lb_origin" 1
snatpool $::remoteDCSnatPool
pool $failoverPool
}
}
}
when LB_FAILED {
if { $failover == 1 } { reject }
LB::down
LB::detach
log local0. "reached LB_FAILED, [active_members $defaultPool] active members"
if { [active_members $defaultPool] < 1 } {
if { [HTTP::header exists lb_origin] } {
log local0. "lb_origin detected, rejecting"
reject
} else {
log local0. "Failing over to $failoverPool"
set failover 1
HTTP::header insert "lb_origin" 1
snatpool $::remoteDCSnatPool
LB::reselect pool $failoverPool
}
} else {
LB::mode rr
LB::reselect
}
}
Edited for formatting