Forum Discussion
Ray_Allen_75591
Nimbostratus
Nov 07, 2014TMSH How to add a irule to a vip with existing irules
I found the script RemoveIruleFromMulttipleVS which works great to remove a irule fom vips that have the same irule in them . I am looking for a script that will add iruleX to multiple VIPs that have...
R_Marc
Nimbostratus
Nov 07, 2014That would be fairly easy to do with iControl rest. Something like (using perl):
!/usr/bin/perl
use JSON qw( decode_json );
use Getopt::Std;
%opts=();
getopts("b:rv:tl:",\%opts);
sub Usage {
print "Usage: $0 [-b ] [-l ] [-r] [-v virtual] [t]\n";
print "\t -b target a particular node (default targets the active member of each cluster) \n";
print "\t -l : separated rule list\n";
print "\t -r replace rather than add\n";
print "\t -v virtual to operate on, default is all\n";
print "\t -t Test run\n";
exit;
}
if ($opts{h} || (!keys %opts)) {
Usage();
}
print "F5 Admin password:";
system('/usr/bin/stty', '-echo'); Disable echoing
my $pass = <>;
system('/usr/bin/stty', 'echo');
chomp $pass;
print "\n";
my $res = `curl -sk -u admin:$pass -H "Content-Type: application/json" -X GET https://$opts{b}/mgmt/tm/ltm/virtual`;
$decoded = decode_json($res);
foreach my $item ( @{$decoded->{'items'}}) {
my $json = "{\"name\":\"$item->{'name'}\",\"rules\":[ ";
if ($opts{v} ) {
if ( ! ($item->{'name'} =~ /$opts{v}/) ) {
next;
}
}
if ( $opts{r} || !(exists($item->{'rules'}))) {
foreach my $rule (split(/:/,$opts{l})) {
$json .= "\"$rule\",";
}
chop $json;
$json .= "] }";
} elsif (exists($item->{'rules'})) {
foreach my $rule ( @{$item->{'rules'}} ) {
$json .= "\"$rule\",";
}
foreach my $rule (split(/:/,$opts{l})) {
$json .= "\"$rule\",";
}
chop $json;
$json .= "] }";
}
if ($opts{t}) {
print "curl -sk -u admin:$pass -H \"Content-Type: application/json\" -X PATCH https://$opts{b}/mgmt/tm/ltm/virtual/$item->{'name'} -d '$json'\n";
} else {
`curl -sk -u admin:$pass -H "Content-Type: application/json" -X PATCH https://$opts{b}/mgmt/tm/ltm/virtual/$item->{'name'} -d $json`;
}
}
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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