Remove iRule From Multiple Virtual Servers (Fork /w multiple partition support)
Problem this snippet solves: Credits: Fork from https://devcentral.f5.com/codeshare?sid=310
The outlined script will detach an iRule from one or more virtual servers. I've added code to the origin...
Updated Jun 06, 2023
Version 2.0Kai_Wilke
My name is Kai Wilke and I'm working as a Principal Consultant for IT-Security at itacs GmbH - a German consulting company specialized in Microsoft Security cloud solutions, F5 customizations as well as for classic IT-Consulting.
You can find additional information about me and my work here:
https://devcentral.f5.com/articles/q-a-with-itacs-gmbhs-kai-wilke-devcentrals-featured-member-for-february-24890MVP
Xterminator
Jul 31, 2019Nimbostratus
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