Tech Tips on DevCentral
   
You are here: Tutorials > Tech Tips

Current Articles | Categories | Search | Syndication

pyControl Apps #2 - Deleting BIG-IP Routes

by Jason Rahm - 3506 views

Last time out I built the foundation of a route management application which grabs the routing table from the BIG-IP utilizing the python implementation of iControl called pyControl.  This time, we'll extend the application with a route deletion function.

New iControl SDK Method --> delete_static_route

This method takes one parameter, routes, in the form of a dictionary with the keys specified as destination and netmask.  Adding routes takes a little extra effort, but that's all we need to delete a route.

New CLI Methods

As this effort is expanding, I saw the need to not just accept arguments, but to offer options as well.  For example, you may just want to view the route table, Or you may want to delete or add a route.  That becomes cumbersome on trying to remember where your arguments go, and counting arguments, etc, for the different use cases.  So I switch from system arguments to the optparse module.  It's pretty simple, specify the flags and what they do, how to reference them, etc.  This code is basic:

        from optparse import OptionParser
        parser = OptionParser()
       
        parser.add_option("-d",  "--device",  action="store", type="string",  dest="host")
        parser.add_option("-u", "--username",  action="store", type="string",  dest="uname")
        parser.add_option("-r",  "--delRoute",  action="store",  type="string",  dest="delrouteFileName")
        parser.add_option("-a",  "--addRoute",  action="store",  type="string",  dest="addrouteFileName")
        (options, args) = parser.parse_args()

        if options.delrouteFileName:
            del_tmmRoutes(rt,  options.delrouteFileName)

 

-h seemed natural for hostname, but it is builtin as help, so I couldn't touch that one.  So I used -d for device, but I also wanted -d for delete, but -r for remove works just as well.

Specifying the -r flag expects a file name, which in my example I aptly called routes.txt.  Format for the file should have a header row with destination and netmask, then the actual routes you want deleted:

destination,netmask
172.16.1.0,255.255.255.0
172.16.2.0,255.255.255.0
172.16.10.0,255.255.255.0

Now that I have the externals in place, I need to create the del_tmmRoutes function to pull that data in from the file, format it, then delete the routes.  This is accomplished in this function:

def del_tmmRoutes(obj,  filename):
   
    routefile = open(filename,  'r')
    headers = routefile.readline().strip().split(',')
    stored_rows = []
   
    for line in routefile:
        route = line.strip().split(',')
        stored_rows.append(dict(zip(headers,  route)))


    for route in stored_rows:
        obj.delete_static_route(routes = [route])
        print "Deleting Route ",  route

 

 When run from the command line, I can see that the rejected routes in my routing table are now deleted:

C:\dev\pyScripts>python ltmRouteManager_new.py -u admin -d 10.10.20.5 -r routes.txt
admin, enter your Password:
 Loading WSDL: Networking.RouteTable.wsdl
Deleting Route  {'netmask': '255.255.255.0', 'destination': '172.16.1.0'}
Deleting Route  {'netmask': '255.255.255.0', 'destination': '172.16.2.0'}
Deleting Route  {'netmask': '255.255.255.0', 'destination': '172.16.10.0'}



TMM IP Routes: (net mask ip)
        0.0.0.0 0.0.0.0 10.10.20.1



TMM Pool Routes: (net mask pool)



TMM Vlan Routes: (net mask vlan)
        172.17.1.0 255.255.255.0 mgmt_tools
        172.17.2.0 255.255.255.0 mgmt_tools
        172.17.10.0 255.255.255.0 mgmt_tools



TMM Rejected Routes: (net mask)

 

The wiki entry for the pyControl route management script has been updated to reflect these changes.



Rate This Article:

COMMENTS

There are currently no comments, be the first to post one.
Only registered users may post comments.
  
Subscriptions: Video  |  Audio  |  Tutorials  |  Tech Tips  |  Features  | 

More...

 

 

Essentials Quick Start Guides
iRules Wiki | iControl SDK | WebAccelerator Wiki iRules | iControl
FirePass Wiki | Advanced Design & Config Wiki WebAccelerator | FirePass

 

Videos

  

Audio

Cache in with LTM and iRules
Can iRules fix my cert mismatch errors?
Concurrent iControl Programming Explained
Cookie LoJack vi iRules
Creating An iControl PowerShell Monitoring Dashboard With Google Charts
Custom SNMP Traps
Exchange Persistence Duality and iRules
FTPS Offload via iRules
Getting Started with pyControl
iControl 101 - #19 - Time Conversions
iControl 101 - #20 - Port Lockdown
iControl 101 - #21 - Rate Classes
iControl 101 - #22 - GTM Data Centers
iControl Apps - #04 - Graceful Server Shutdown
iControl Apps - #05 - Rate Based Statistics
iControl Apps - #06 - Configuration Archiving
iControl Apps - #07 - System Http Statistics
iControl Apps - #08 - System IP Statistics
iControl Apps - #09 - TMM Statistics
iControl Apps - #10 - Bigpipe List
iControl Apps - #11 - Global GTM Statistics
iControl Apps - #12 - Global SSL Statistics
iControl Apps - #13 - System PVA Statistics
iControl Apps - #14 - Global Statistics
iControl Apps - #18 - Virtual Server Reverse Lookup
Investigating the LTM TCP Profile: Acknowledgements
Investigating the LTM TCP Profile: Congestion Control Algorithms
Investigating the LTM TCP Profile: ECN & LTR
Investigating the LTM TCP Profile: Max Syn Retransmissions & Idle Timeout
Investigating the LTM TCP Profile: Nagle’s Algorithm
Investigating the LTM TCP Profile: The Finish Line
Investigating the LTM TCP Profile: Windows & Buffers
iRules 101 - #13 - TCL String Commands Part 1
iRules 101 - #14 - TCL String Commands Part 2
iRules 101 - #15 - TCL List Handling Commands
iRules Event Order
Managing The System Boot Location with iControl
Persisting SSL Connections
Replacing the WebSphere Apache Plugin with iRules
Ruby meets iControl: Creating VIPs
Ruby meets iControl: Making Wide IPs
Ruby Meets iControl: Switching Policies
Ten Steps to iRules Optimization
Unbind your LDAP servers with iRules
v.10 - A new iRules Namespace
v.10 - FastHTTP and Cookie Persistence
v.10 - iRules and the after command
v.10 - New class features in iRules
v.10 - Remote Authorization via TACACS+
v10.1 - Configuring GTM's DNS Security Extensions

  

Features

  

Tutorials

  

iControl

  

iRules

  

Monitoring & Management

  

Advanced Design & Config

  

93,050 Members in 191 Countries and Growing!

Join DevCentral Today!

About DevCentral

F5 DevCentral is your source for the best technical documentation, discussion forums, blogs, media and more related to application delivery networking.

So dive in, meet your peers, and get familiar with DevCentral. We hope it makes your job easier and helps you get more from your F5 investment. If new to DevCentral, check out the Getting Started section. And if you have any problems, or think something could be easier to use, let us know.

Got It !

We've received your comment and transmitted it directly to DevCentral HQ.

Thanks for taking time to let us know what's on your mind. At DevCentral | Community Matters!

Get In Touch With Us

Have questions, suggestions or just want to get something off your chest?

Use our handy form below to Direct Connect with DevCentral Mission Control.

Send Us Feedback      or