Forum Discussion
Syntax to Map Virtual-Server's Character with Data-Group which Contains Pool Name
Kindly have a look into the below Irule:
1.Last part of the Data-Group: dg_parveez_dynamic_pools contains a list of all dynamic pools: 2.Idea is to apply/create a single Irule into the future and attact that into the new Virtual-Servers, and based on that we are planning to add the new dynamic pool into the Data-group created, to make operation task easy and error free. 3. Challenge is: When the user hit the Virtual-server, it should go to the correct Pool which will serve him the request, while matching the name.
when CLIENT_ACCEPTED { set default_pool [LB::server pool] log local0. "Default pool [LB::server pool] set" log local0. "Client IP is [IP::remote_addr]" }
when HTTP_REQUEST {
switch -glob [HTTP::uri] {
"/" {
log local0. "redirecting from /"
HTTP::redirect "http://http://www.lenovo.com/us/en"
return
pool pool_lenovo.com-http
}
"/iss_static*" {
pool $static_pool
return
}
default {
pool [class match -element [string tolower [virtual]] starts_with dg_parveez_dynamic_pools ]
return
}
}
}
- Example of the naming convention of the Virtual-Server and Pool mapped against it is:
a) Virtual-Server: apuat.leni2.com-VS-HTTP , Pool : pool_apuat_leni2.com_http b) Virtual-Server: apbuild.leni2.com-VS-HTTP , Pool : pool_apbuild.leni2.com_http c) Virtual-Server: apctdev.leni2.com-VS-HTTP , Pool : pool_apctdev.leni2.com_http
- Query: By comparing the above Irule, whether the below Irule part will fit our requirement, I mean can the Virtual-server will be intelligent enough to send the traffic to the correct dynamic pool to meet the requirement, or do we need to modify this:
Naming Convention of the Virtual-Server and Pool is mentioned into the Point 04:
default { pool [class match -element [string tolower [virtual]] starts_with dg_parveez_dynamic_pools ] return }
Kindly suggest.
Thanks and Regards Parveez
37 Replies
- Parveez_70209
Nimbostratus
Hi Kevin,
Kindly guide ?
Thanks and Regards Parveez
- Kevin_Stewart
Employee
The biggest problem here is that the pool command is expecting the name of a pool only, but your [class match -element ] command is returning the key (virtual server name) and value (pool name) of the data group search as a list.
So if you're data group looks like this:
apuat.leni2.com-vs-http := pool_apuat_leni2.com_http apbuild.leni2.com-vs-http := pool_apbuild.leni2.com_http apctdev.leni2.com-vs-http := pool_apctdev.leni2.com_http
** Notice that the virtual server names are all completely lower case since your class match is doing the same.
Then your class match should more appropriately look like this:
[class match [string tolower [virtual]] equals dg_parveez_dynamic_pools]
This will return the corresponding pool name to be fed into the pool command.
- Parveez_70209
Nimbostratus
Hi Kevin,
I was eagerly waiting for your suggestion into this.
Not very sure how the LETTERS have an affect into the irule, so yes into the example of Virtual-server( VS-HTTP is in capital letter) and Pool name, it is exactly like the below:
apuat.leni2.com-VS-HTTP := pool_apuat_leni2.com_http apbuild.leni2.com-VS-HTTP := pool_apbuild.leni2.com_http apctdev.leni2.com-vs-http := pool_apctdev.leni2.com_http
So, in that case Kevin, can we use the suggested below:
[class match [string tolower [virtual]] equals dg_parveez_dynamic_pools]
And while creating the String Data-Group, whether we need to add exactly as below::
is this is the syntax( Virtual Name := Pool Name) while adding into the Data-Group in our scnenario:
apuat.leni2.com-VS-HTTP := pool_apuat_leni2.com_http apbuild.leni2.com-VS-HTTP := pool_apbuild.leni2.com_http apctdev.leni2.com-VS-HTTP := pool_apctdev.leni2.com_http
Thanks and Regards Parveez
- Kevin_Stewart
Employee
You're doing a [string tolower [virtual]] evaluation, so the key in the data group also needs to be lower case.
For what it's worth, the [virtual] command alone will return the correct name (and case) of the VIP, so you could just get rid of the [string tolower ] part.
- Parveez_70209
Nimbostratus
Hi Kevin,
Sorry for bothering you, but this is just to clear my doubts as we used to get valuable information from your post and we just admire it.
Kindly let me explain what I understood: 1. As we got to know that in our production environment, we have the below format:
virtual-servername-VS-HTTP(virtual-server name small while VS-HTTP Large) and Pool all in same. Example:
a) Virtual-server : apuat.leni2.com-VS-HTTP , Pool : pool_apuat_leni2.com_http
b) Virtual-server : apbuild.leni2.com-VS-HTTP , Pool : pool_apbuild.leni2.com_http
c) Virtual-server : apctdev.leni2.com-VS-HTTP Pool : pool_apctdev.leni2.com_http
- But in our Irule syntax as per suggestion we are going to use:
[class match [string tolower [virtual]] equals dg_parveez_dynamic_pools]
And as into the Irule we are using "string tolower" , so is that mean we need to add all in lower format into the Data-Group like the below ?( but actually the naming convention in production of VS-HTTP is in capital part., so that is fine right incase we add all in small in Data-group ?)
apuat.leni2.com-vs-http := pool_apuat_leni2.com_http
apbuild.leni2.com-vs-http := pool_apbuild.leni2.com_http
apctdev.leni2.com-vs-http := pool_apctdev.leni2.com_http
- I am more comfortable in GUI than CLI, we in case I go to String Data-Group list to add those:
Than in String section, what is the best format to add those ( can we add as same format) into that ? Will the below exact format will work ? (V.S:=Pool)
apuat.leni2.com-vs-http := pool_apuat_leni2.com_http
- Additional Point: for my own knowledge, incase we have environment where the format of the Virtual-server is not as per the standard( lets say some in capital letter while some in small letter and same with pool, but we need to still match the same requirement, how my Irule part will change ?
I mean the below one:
[class match [string tolower [virtual]] equals dg_parveez_dynamic_pools]
Thanks and Regards Parveez
- Kevin_Stewart
Employee
Consider first that the [virtual] command will return the name of the virtual server that is processing this iRule. It's a completely internal process, so there's no chance of a case mismatch. For example, if the virtual server name is literally:
mY_bIg-Ip_ViP
then the [virtual] command will be guaranteed to return:
mY_bIg-Ip_ViP
Given this fact, you shouldn't need to do a [string tolower ] evaluation. The following is more appropriate:
[class match [virtual] equals dg_parveez_dynamic_pools]
Where the [string tolower ] function would be important is anywhere the client could affect the value. So for example, let's say 5 different clients open their browsers and enter the following URI value (respectively):
/this-is-a-test-uri /This-is-a-test-uri /This-is-a-test-URI /This-Is-A-Test-Uri /ThIs-Is-A-tEsT-uRi
In this case you have five different versions of the same URI. The backend server may not care about this, but iRule/TCL evaluations are case-sensitive. So to successfully match all 5 of these URIs, you must "normalize" the input.
if { [string tolower [HTTP::uri]] starts_with "/this-is-a-test-uri" }
Notice that because you're normalizing the input to an all lowercase value, your match string must also be lowercase. The same applies to data group lookups.
- Parveez_70209
Nimbostratus
Hi Kevin,
Awesome, getting cool concepts. Ok a final summarization:
A. Case 1 : Irule format:( using the below)
[class match [virtual] equals dg_parveez_dynamic_pools]
So, into this case my String Data-Group can be added as the original format correct ?
apuat.leni2.com-VS-HTTP := pool_apuat_leni2.com_http
apbuild.leni2.com-VS-HTTP := pool_apbuild.leni2.com_http
apctdev.leni2.com-VS-HTTP := pool_apctdev.leni2.com_http
B. Case 2; Irule format:( using the below)
[class match [string tolower [virtual]] equals dg_parveez_dynamic_pools]
So, in this case my String Data-Group should be added as the lower format. But our requirement still works right despite of the Capital segment of the Virtual-Server Part in Production environment ?
apuat.leni2.com-vs-http := pool_apuat_leni2.com_http
apbuild.leni2.com-vs-http := pool_apbuild.leni2.com_http
apctdev.leni2.com-vs-http := pool_apctdev.leni2.com_http
C.Thirdly : while adding this String-Data-Group up from GUI , kindly verify the steps:
1.On the Main tab of the navigation pane, expand Local Traffic, and click iRules. The iRules screen opens. 2.On the menu bar, click Data Group List. 3.In the upper right corner of the screen, click Create. 4.In the Name box, type a unique name for the data group, such as dg_parveez_dynamic_pools. 5.In the Type box, select String. The screen expands to show the string-specific settings. 6.In the String box, type the first string for the data group. 7.Click Add. 8.Click Finished.
While adding the same is the format good ? Concentrating into := , is that correct.
apuat.leni2.com-vs-http := pool_apuat_leni2.com_http
Thanks and Regards Parveez
- Kevin_Stewart
Employee
A: correct B: correct C: correct
- Parveez_70209
Nimbostratus
Thank you so much Kevin,
- Adding one more point related to the part related to /iss_static content( mentioned into my first reply post into this topic), which generally used for customer's static pages:
"/iss_static*" { pool $static_pool return
- Currently there are only 3 pools against the same named as, might be in future these may also increase:
pool_confarma1.leni2.com_http
pool_confarma2.leni2.com_http
pool_confarma3.leni2.com_http
-
So, in actual Irule, one of these pools are manually selected/mentioned in place of static_pool.
-
So, as this is also associated with earlier mentioned Virtual-Servers:
apuat.leni2.com-VS-HTTP
apbuild.leni2.com-VS-HTTP
apctdev.leni2.com-VS-HTTP
Biggest challenge is these Virtual-Server's naming convention is not matching with the pools mentioned against the static_pools.
So, query:
A) Can we apply here also a Data-Group lets say named as dg_parveez_static_pools ? B) Can we take the same Format while adding up into the String list ?
apuat.leni2.com-VS-HTTP:=pool_confarma1.leni2.com_http
apbuild.leni2.com-VS-HTTP:=pool_confarma2.leni2.com_http
apctdev.leni2.com-VS-HTTP:=pool_confarma3.leni2.com_http
C) Can the same Irule format will apply for this too ?
[class match [virtual] equals dg_parveez_static_pools]
If yes , kindly suggest the final Irule by editing the below:
when CLIENT_ACCEPTED { set default_pool [LB::server pool] log local0. "Default pool [LB::server pool] set" log local0. "Client IP is [IP::remote_addr]" }
when HTTP_REQUEST {
switch -glob [HTTP::uri] { "/" { log local0. "redirecting from /" HTTP::redirect "http://www.parveez.com" return pool pool_parveez.com-http } "/iss_static*" { pool $static_pool return } default { [class match [virtual] equals dg_parveez_dynamic_pools] return } }
}
Thanks and Regards Parveez
- Kevin_Stewart
Employee
Give this a shot:
when CLIENT_ACCEPTED { set default_pool [LB::server pool] log local0. "Default pool [LB::server pool] set" log local0. "Client IP is [IP::remote_addr]" } when HTTP_REQUEST { switch -glob [string tolower HTTP::uri]] { "/" { log local0. "redirecting from /" HTTP::redirect "http://www.parveez.com" return pool pool_parveez.com-http } "/iss_static*" { if { [class match [virtual] equals dg_parveez_static_pools] } { pool [class match -value [virtual] equals dg_parveez_static_pools] } else { log local0. "Static pool entry for [virtual] not created yet" reject } return } default { if { [class match [virtual] equals dg_parveez_dynamic_pools] } { pool [class match -value [virtual] equals dg_parveez_dynamic_pools] } else { log local0. "Dynamic pool entry for [virtual] not created yet" reject } return } } }
I fixed up some of the other syntax and added conditions for the possibility of there not being a data group entry for a given virtual server name (ie. you hadn't created it yet). This will keep the iRule from bombing on a null pool value.
You could also streamline this a little by using the same data group for both. If you put the dynamic pool and the static pool (comma separated) in the same value block, then you can use this value like a list. Example:
apuat.leni2.com-VS-HTTP := pool_apuat_leni2.com_http,pool_confarma1.leni2.com_http apbuild.leni2.com-VS-HTTP := pool_apbuild.leni2.com_http,pool_confarma2.leni2.com_http apctdev.leni2.com-VS-HTTP := pool_apctdev.leni2.com_http,pool_confarma3.leni2.com_http
And then your iRule might look like this:
when CLIENT_ACCEPTED { set default_pool [LB::server pool] log local0. "Default pool [LB::server pool] set" log local0. "Client IP is [IP::remote_addr]" } when HTTP_REQUEST { switch -glob [string tolower HTTP::uri]] { "/" { log local0. "redirecting from /" HTTP::redirect "http://www.parveez.com" return pool pool_parveez.com-http } "/iss_static*" { if { [class match [virtual] equals dg_parveez_static_pools] } { pool [lindex [split [class match -value [virtual] equals dg_parveez_static_pools] ","] 1] } else { log local0. "Static pool entry for [virtual] not created yet" reject } return } default { if { [class match [virtual] equals dg_parveez_dynamic_pools] } { pool [lindex [split [class match -value [virtual] equals dg_parveez_dynamic_pools] ","] 0] } else { log local0. "Dynamic pool entry for [virtual] not created yet" reject } return } } }
The data group query will return a comma delimited set of values. Example:
dynamic_pool,static_pool
So you'll first split this value on the comma to make a list, and then extract either the first or second element with the lindex command.
Recent Discussions
Related Content
* 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