Forum Discussion
ML_108504
May 11, 2012Nimbostratus
Most efficient way to re-prioritize a virtual server's iRules?
Hi folks,
I'm writing a powershell script to add and remove a maintenance page redirect iRule to the top of a given virtual server's iRule list (TMOS versions 9.4.x and 10.x). Any given virtual server that this script would run against would already have a list of iRules applied to it.
To my chagrin, it appears that there's no way to directly change the priority of iRules already assigned to a virtual server, so it seems that I have to:
1. dump the existing list of iRules (and their original priorities) to a 2-dimensional array (storing .rule_name and .priority)
2. add 1 to the value of all their priorities
3. add the maintenance page redirect iRule to the virtual server (with a priority of 0)
4. add back all of the original iRules with their modified priorities
5. do the reverse when it's time to remove the maint page redirect iRule
NOTE: I could store the original irule names and priorities, NOT change their priorities, and then just add them back after removing the maint page redirect iRule, but then I'd need to reliably store the original iRule information somewhere where ANYONE on the team can re-apply the original iRules from any of a number of different workstations, and it's just not worth the additional complexity. By leaving all of the original iRules applied to the virtual (with modified priorities) it's easy for any admin running the script to remove the maint redirect iRule at any time, from any of their workstations. Anyway ...
I was going to simply dump the results of this query to a 2-dimensional array, but the results appear to come back as one field:
PS C:\> $rule_list = (Get-F5.iControl).LocalLBVirtualServer.get_rule((, $vs_name))
PS C:\> $rule_list | Format-Table -AutoSize
rule_name priority
--------- --------
iRule_go2_tst_icontrol_pageA 0
iRule_go2_tst_icontrol_pageB 1
PS C:\> $rule_list.count
1
Can anyone please suggest the most efficient way to do this sort of iRule priority swapping via iControl and Powershell?
Thank you!
- George_Watkins_Historic F5 AccountHi ML,
priority 100 when HTTP_REQUEST { HTTP::redirect "http://mysite.com/maintenance.html" }
- ML_108504NimbostratusThanks for the reply watkins!
- George_Watkins_Historic F5 AccountYes, the priorities that are returned from iControl are the GUI orderings, which are different from priorities defined in an iRule. Both determine the order of execution, but the Gui order is only used to resolve equal priorities in multiple iRules. The iRules priority command that I am referencing changes the internal priority in which the iRules are executed and takes precedence over the GUI ordering.
-George
- ML_108504NimbostratusAha, got it, thanks for the generous explanation!
- ML_108504NimbostratusOK, bit of follow up here and more questions.
- ML_108504NimbostratusOK, here is the essence of my outage iRule:
priority 100 when HTTP_REQUEST { HTTP::redirect "http://www.outagesite.com/dir/sorrypage.html" event disable }
When I browse to the redirect URL directly (http://www.outagesite.com/dir/sorrypage.html), the sorry page comes up fine.when HTTP_REQUEST { set host "wwwt.testsite.com" set Dir1 [string tolower [getfield [HTTP::uri] "/" 2]] set Dir2 [string tolower [getfield [HTTP::uri] "/" 3]] switch -glob $Dir1 { "uri_A" - "uri_B" - "uri_C" { pool p_test_A_http } "uri_D" - "uri_E" { pool p_test_B_http } "uri_F" { switch -glob $SCEDir2 { "uri_X" - "uri_Y" - "uri_Z" { pool p_test_X_http } } } default { pool p_test_Z_http } } }
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