F5 is upgrading its customer support chat feature on My.F5.com. Chat support will be unavailable from 6am-10am PST on 1/20/26. Refer to K000159584 for details.

Forum Discussion

Ray_Allen_75591's avatar
Ray_Allen_75591
Icon for Nimbostratus rankNimbostratus
Nov 07, 2014

TMSH 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 existing irules and will not remove the existing irules .

 

Thanks

 

1 Reply

  • R_Marc's avatar
    R_Marc
    Icon for Nimbostratus rankNimbostratus

    That 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`;
            }
    
    }