Remove iRule From Multiple Virtual Servers (Fork /w multiple partition support)
Updated Jun 06, 2023
Version 2.0Was this article helpful?
Hello, thanks for the script
Adapted it to contain also eventual keywords, in order to delete the specified iRule from Virtual Servers which have a specific naming convention (e.g. application.test.bank.com). Just contains one more IF-THEN clause:
proc script::run {} {
if { $tmsh::argc != 2 } then {
puts "A single rule name must be provided"
exit
}
set qualified_rulename [lindex $tmsh::argv 1]
set vips_in_play ""
foreach partition [tmsh::get_config auth partition] {
set partition "/[tmsh::get_name $partition]"
puts "Crawling Partition: $partition"
tmsh::cd $partition
if { $qualified_rulename starts_with $partition } then {
set rulename [string range $qualified_rulename [expr { [string last "/" $qualified_rulename] + 1 } ] end]
} else {
set rulename $qualified_rulename
}
set vips [tmsh::get_config /ltm virtual]
tmsh::begin_transaction
foreach vip $vips {
if { $vip contains "KEYWORD" } then {
puts "\tCrawling VS : $partition/[tmsh::get_name $vip]"
if { [tmsh::get_field_value $vip "rules" rules] == 0 } then {
puts "\tFinished VS: No Rules bound to the VS"
continue
}
if { [lsearch -exact $rules $rulename] == -1 } then {
puts "\tFinished VS: $rulename is not bound to VS"
continue
}
if { [llength $rules] < 2 } then {
puts "\tFinished VS: $rulename is getting removed from VS"
tmsh::modify /ltm virtual [tmsh::get_name $vip] rules none
} else {
puts "\tFinished VS: $rulename is getting removed from VS"
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 "$partition/[tmsh::get_name $vip]"
}
}
tmsh::commit_transaction
puts "Finished Partition: $partition"
}
if { $vips_in_play ne "" } then {
puts "The iRule $rulename was removed from the following virtuals:"
foreach vip_in_play $vips_in_play {
puts "\t$vip_in_play"
}
} else {
puts "The iRule $rulename was not found on any virtual."
}
}
Regards