Python Bigsuds - Massive iRule removal

Problem this snippet solves:

The goal of this script is to do a massive removal of a previously deployed iRule. It will search for iRule name applied on Virtual Server and will remove it.

Code :

# This python script is used to remove a specific iRule for ALL VS
import bigsuds
import sys
b = bigsuds.BIGIP(
hostname = 'ip',
username = 'admin',
password = 'admin',
except Exception, e:
print e
#Change system partition
virtualservers = b.LocalLB.VirtualServer.get_list()
rules = b.LocalLB.VirtualServer.get_rule(virtualservers)
rule_to_remove = '/mypartition/myiRulename'
irules_list = b.LocalLB.Rule.get_list()
found_rule = False

# check if iRule is present
for irule in irules_list:
if irule == rule_to_remove:
found_rule = True
if found_rule:
print "Found iRule with name: %s" % rule_to_remove
print "iRule not Found"
count = 0
for vs in virtualservers:
print "\n\nVS: %s" % vs
for rule in rules[count]:
print "\tRules %i: %s" % (count, rule)
    count += 1
count = 0
for id_rule in rules:
for rule in id_rule:
  if rule["rule_name"] == rule_to_remove:
b.LocalLB.VirtualServer.remove_rule([virtualservers[count]], [[rule]])
print "\nRemove rule: %s, from vs: %s" % (rule, [virtualservers[count]])
except Exception, e:
print e
    count +=1
Published Mar 09, 2015
Version 1.0

Was this article helpful?

No CommentsBe the first to comment