For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

ccna55_14039's avatar
ccna55_14039
Icon for Nimbostratus rankNimbostratus
Oct 20, 2014

Python Bigsuds - Massive iRule removal - bigsuds script for massive iRule removal

I am testing this python script to be able to do a mass irule removal.

It appears there is an issue with

    except Exception, e:
         ^
SyntaxError: invalid syntax

Here is the snip of that lines before and after

I have not done anything to the orginal script except to line up the tab's and indent's.

Here is where this script lives.

https://devcentral.f5.com/wiki/iControl.Python-Bigsuds-Massive-iRule-removal.ashx

Line 51 on that page would be the line that give the error.

I see on various websites this syntax was an issue pre 2.6 but i am running

Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)]

for id_rule in rules:
if rule["rule_name"] == rule_to_remove:
    try:
        b.LocalLB.VirtualServer.remove_rule([virtualservers[count]], [[rule]])
  print "\nRemove rule: %s, from vs: %s" % (rule, [virtualservers[count]])
    except Exception, e:
    print e
 break
        count +=1

Any help would be greatly appreciated as this is my first time using python.

Thanks,

ccna55

2 Replies

  • It appears there is an issue with indentation. Does this snippet in your example have the same indentation as the file as it appears on your 2.7.3 system?

    The parts to 'try' should be indented equally:

    for
      if
        try:
           b.LocalLB
           print
        except Exception, e:
           print e
           break
      count...   if that's where it belongs with your logic
    
  • Thanks very much for this info, With this i was able to fix the script.

     

    Much Appreciated.

     

    ccna55