Forum Discussion
boneyard
Mar 07, 2012MVP
looking to optimize / generalize irule
i have an irule which selects a pool based on several known items (think: uri, client ip, port). i have many of these sets, so some strings and a poolname. currently this is all hard coded in the irule, which means many variables.
looking ahead this isnt a nice way to handle things and only becomes worse with every addition. id like to do this better and think data groups / classes can be a solution. (if there is an other one im open to it for sure).
i was thinking about having a data group per set of strings and pool. but that would mean having all the data group names hard coded in the irule right? is there some way to work around this? one thing i thought might work is having a "super" data group containing the names of the other data groups, would that work?
to look at it in another way: if i would do something like this in an other language i would use an array filled with arrays, but im not sure how to do it in an irule.
6 Replies
Sort By
- Hi Boneyard,
- don't think i fully see the plan, are you suggesting something like below (i apologize for the bad pseudo code, dont have a f5 around now and removed a variable for keeping it small):
- I was thinking of having one set of data groups per virtual server. Maybe I've misunderstood your scenario. Can you clarify what logic you use to tie together the URIs, ports and pools?
- checked the above and this indeed works.
if { [class match -value ip equals [virtual name]_class] == [IP::client_addr] and [class match -value port equals [virtual name]_class] == [TCP::local_port]} { set pool [class match -value pool equals [virtual name]_class] log local0. "$pool" pool $pool }
- looked around some more and found an alternative which will do the trick i believe, would this be acceptable code or is there something to change / make better?
class all_app_classes { class_app1 class_app2 } class class_app1 { "ip" {"192.168.34.23"} "port" {"45"} "pool" {"pool_1"} } class class_app2 { { "ip" {"192.145.224.23"} "port" {"55"} "pool" {"pool_2"} } set id [class startsearch all_app_classes] while { [class anymore all_app_classes $id] } { set x [class nextelement all_app_classes $id] set app_class [lindex $x 0] log local0. "$app_class" if { [TCP::local_port] == [class match -value port equals $app_class] and [IP::client_addr] == [class match -value ip equals $app_class] } { log local0. "$app_class is the right class" set saved_class $app_class } } pool [class match -value pool equals $saved_class]
- Yep, that seems like it should work in concept. Will you have multiple ip-port-pool combinations per application? If not, you could combine the data groups into one:
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