Rapid iRule Removal via Tmsh Script
The BIG-IP GUI is pretty slick and there have been massive improvements in function and efficiency since my first exposure in version 4.2. As good as it is, however, some tasks are just better suite...
Published May 14, 2010
Version 1.0JRahm
Admin
Joined January 20, 2005
JRahm
Admin
Joined January 20, 2005
Ariel_Santa_Cr1
Sep 02, 2013Historic F5 Account
Hi Jason,
I was trying to modify this iRule to achive the same objective but in every partition. I've been with this script the whole day and get to the approach below. The only problem I'm having is that the lsearch is not matching the rule name with the rules list, may be due to the complete name is with the partition name. Also tried to pass the complete path as /Common/rule_name, and other test to remove the -exact option to the lsearch command, non of this worked.
What am I missing?
Commented iRule.
proc script::init {} {
}
proc script::run {} {
if { $tmsh::argc != 2 } {
puts "A single rule name must be provided"
exit
}
set rulename [lindex $tmsh::argv 1]
set rules ""
read the partitions list and store it in a variable
set partitions [tmsh::get_config /auth partition]
set vips_in_play ""
foreach partition $partitions {
changing the active partition
tmsh::cd "/[tmsh::get_name $partition]"
reading the virtual servers list for the active partition
set vips [tmsh::get_config /ltm virtual]
begining the transaction here as the get_config function can't be invoked within a transaction
tmsh::begin_transaction
foreach vip $vips {
if { [tmsh::get_field_value $vip "rules" rules] == 0 } {
continue
}
here's the problem I found, this lsearch returns always -1 even when the rulename is in the rules list. To test it I removed the -exact option but still not working.
if { [lsearch $rules $rulename] == -1 } {
continue
}
puts "Pase por aqui: $vip"
if { [llength $rules] < 2 } {
tmsh::modify /ltm virtual [tmsh::get_name $vip] rules none
lappend vips_in_play $vip
} else {
set id [lsearch -exact $rules $rulename]
set keepers [lreplace $rules $id $id]
tmsh::modify /ltm virtual [tmsh::get_name $vip] rules "{ $keepers }"
lappend vips_in_play $vip
}
}
Commiting the transaction within this foreach to be able to run the get_config for the next partition.
tmsh::commit_transaction
}
puts "The $rulename iRule was removed from the following virtuals: "
foreach x $vips_in_play {
puts "\t[tmsh::get_name $x]"
}
}
Any help will be much appreciated.
Ariel