Forum Discussion
Ravi_Rajan_7549
Nimbostratus
Mar 17, 2008Redirection with Multiple pools
Hi,
I am not very experienced with irules and have few queries as below -
I have two pools ex. poola and poolb. Each pool has few servers like -
poola - server1, server2
poolb - server3, server4.
Server1 & Server2 -
These servers are hosting web applications with URI - /abc and /xyz
Server3 & Server4-
These servers are hosting web applications with URI /pqr and /def
Now i have a single virtual server and i need an irule which does something like this -
For each incoming request, the irule should check the URI and based on URI, it should use the appropriate pool.
For ex - In case URI is /abc, then the virtual server should poola and If URI is /def then the virtual server should use poolb.
TIA,
Regards,
Ravi
14 Replies
- The_Bhattman
Nimbostratus
Hi Ravi
The code could look something like the following:when HTTP_REQUEST { switch [HTTP::uri] "/abc" - "/xyz" { pool poola } "/pqr" - "/def" { pool poolb } } }
Keep in mind that the code can be written in IF-ELSE logic, but switch statement will look a bit cleaner for this particular situation.
You can learn more about switch statements from the following link
http://devcentral.f5.com/Default.aspx?tabid=63&articleType=ArticleView&articleId=129
thanks,
CB - Ravi_Rajan_7549
Nimbostratus
Hi,
Thanks for the below. One more addition to the above, is that there may be some applications which i would like to go with the default pool itself.
Also, can we use datagroups instead ?
Thanks,
Ravi - The_Bhattman
Nimbostratus
There is a setting in the pool configuration where you can select the default pool. If the irules fail or it doesn't select the pool the default pool is choosen.
Yes You can also use datagroups with an if argument.
/CB - Ravi_Rajan_7549
Nimbostratus
Hi,
Thanks. As i am new to irules, it would be helpful if you can give a sample code using datagroups where in datagroup1 will have /abc & /xyz and datagroup2 will have /pqr & /def. Also, instead of [HTTP::uri], would like to use - string tolower [HTTP::uri]
TIA,
Ravi - The_Bhattman
Nimbostratus
The class object can be defined in the followingclass dg_poola { "/abc" "/xyz" } class dg_poolb { "/prq" "/def" }
The irule can be written so it uses the datagroup along with 'string tolower' argument.when HTTP_REQUEST { if { [matchclass [string tolower [HTTP::uri]] contains $::dg_poola] } { pool poola } else if { [matchclass [string tolower [HTTP::uri]] contains $::dg_poolb] } { pool poolb } } }
/cb - Ravi_Rajan_7549
Nimbostratus
Hi,
Thanks for the below. I will test it out.
In case of huge number of pools, can this be rewritten with a switch statement ?
Regards,
Ravi - Nicolas_Menant
Employee
Hi,
in case of huge number of pools you may use this method:
class mylist {
"/this pool1"
"/that pool2"
}
when HTTP_REQUEST {
set lookup [HTTP::path]
set myPool [findclass $lookup $::mylist " "]
if {$myPool != ""}{
pool $myPool
}
}
You have the syntax here: Click here
Be careful if you have uri starting with the same directory that should load balance different pools. With findclass it will stop at the first line in your class that match the request
if that's the case you may have a look here: Click here - The_Bhattman
Nimbostratus
nmenant beat me to it.
Here is the same method using Ravi's parametersclass dg_poolchoice { "/abc poola" "/xyz poola" "/prq poolb" "/def poolb" } when HTTP_REQUEST { set choosenpool [findclass [string tolower [HTTP::uri]] $::dg_poolchoice " "] if { $choosenpool != "" } { pool $choosenpool } }
/CB - Ravi_Rajan_7549
Nimbostratus
Thanks a lot, earlier one worked fine. I will try this one too. This may be more cost effective in terms of CPU cycles.
Ravi - Nicolas_Menant
Employee
Hi,
if you have a huge number of different pools to select it's better to use classes.
Usually we recommend to use switch for a number of tests which is < 100 and classes when you have more than 100 entries.
HTH
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
