Subscriptions: Video  |  Audio  |  Tutorials  |  Tech Tips  |  Features  |  More...

Current Articles | Categories | Search | Syndication

by citizen_elah - 2039 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.
Audio
Validating Data Group (Class) References
v10.1 - Configuring GTM's DNS Security Extensions
v.10 - Remote Authorization via TACACS+
v.10 - New class features in iRules
v.10 - iRules and the after command
v.10 - FastHTTP and Cookie Persistence
v.10 - A new iRules Namespace
Unbind your LDAP servers with iRules
Ten Steps to iRules Optimization
Tech Tip: Saving Your iControl Changes
Switch Gone Wild: Using Wildcards with the Tcl "switch" command
Stacking iRules: A Modular Approach
SNMP: Capturing SSL Statistics per Virtual Server
Selective DNS Persistence on GTM
Ruby Meets iControl: Switching Policies
Ruby meets iControl: Making Wide IPs
Ruby meets iControl: Creating VIPs
Rewriting Redirects
Replacing the WebSphere Apache Plugin with iRules
RADIUS Load Balancing with iRules
Polymorphism - Making TCL operators work for you
Persisting SSL Connections
Persisting Across Virtual Servers
Passive Application Monitoring with LTM
Monitoring TCP Applications #01
Managing The System Boot Location with iControl
LTM: Per-VLAN Default Gateways
LTM: Dueling Timeouts
LTM: Configuring IP Forwarding
LTM: Action on Service Down
iRules: Disabling Event Processing
iRules Update: New options for the "log" command
iRules Optimization 101 - #05 - Evaluating iRule Performance
iRules Optimization 101 - #04 - Delimiters: Braces, Brackets, Quotes and more
iRules Optimization 101 - #03 - for vs. foreach
iRules Optimization 101 - #02 - Expressions and Variables
iRules Optimization 101 - #01 - if, elseif and switch
iRules Event Order
iRules 101 - #15 - TCL List Handling Commands
iRules 101 - #14 - TCL String Commands Part 2
iRules 101 - #13 - TCL String Commands Part 1
iRules 101 - #12 - Validating Your Logic
iRules 101 - #11 - Events
iRules 101 - #10 - Regular Expressions
iRules 101 - #09 - Debugging
iRules 101 - #08 - Classes
iRules 101 - #07 - Catch
iRules 101 - #06 - When
iRules 101 - #05 - Selecting Pools, Pool Members, and Nodes
iRules 101 - #04 - Switch
iRules 101 - #03 - Variables
iRules 101 - #02 - If and Expressions
iRules 101 - #01 - Introduction to iRules
iRule Security 101 - #09 - Command Execution
iRule Security 101 - #08 - Limiting POST Data
iRule Security 101 - #07 - FTP Proxy
iRule Security 101 - #06 - HTTP Referer
iRule Security 101 - #05 - Avoiding Path Traversal
iRule Interference: Custom Closes and Responses
Investigating the LTM TCP Profile: Windows & Buffers
Investigating the LTM TCP Profile: The Finish Line
Investigating the LTM TCP Profile: Nagle’s Algorithm
Investigating the LTM TCP Profile: ECN & LTR
Investigating the LTM TCP Profile: Congestion Control Algorithms
Investigating the LTM TCP Profile: Acknowledgements
iControl Concept to Implementation (iC2I): The Introduction.
iControl Apps - #18 - Virtual Server Reverse Lookup
iControl Apps - #14 - Global Statistics
iControl Apps - #13 - System PVA Statistics
iControl Apps - #12 - Global SSL Statistics
iControl Apps - #11 - Global GTM Statistics
iControl Apps - #10 - Bigpipe List
iControl Apps - #09 - TMM Statistics
iControl Apps - #08 - System IP Statistics
iControl Apps - #07 - System Http Statistics
iControl Apps - #06 - Configuration Archiving
iControl Apps - #05 - Rate Based Statistics
iControl Apps - #04 - Graceful Server Shutdown
iControl Apps - #03 - Local Traffic Map
iControl Apps - #02 - Local Traffic Summary
iControl Apps - #01 - Disabling Node Servers
iControl 101 - #22 - GTM Data Centers
iControl 101 - #21 - Rate Classes
iControl 101 - #20 - Port Lockdown
iControl 101 - #19 - Time Conversions
iControl 101 - #18 - Stream Profile
iControl 101 - #17 - PortMirror
iControl 101 - #16 - SelfIPs
iControl 101 - #15 - System Services
iControl 101 - #14 - License Administration
iControl 101 - #13 - Data Groups
iControl 101 - #12 - Database Variables
iControl 101 - #11 - Performance Graphs
iControl 101 - #10 - System Inet
iControl 101 - #09 - iRules
iControl 101 - #08 - Partitions
iControl 101 - #07 - User Management
iControl 101 - #06 - File Transfer APIs
iControl 101 - #05 - Exceptions
iControl 101 - #04 - Language Options
iControl 101 - #03 - iControl Taxonomy
iControl 101 - #02 - How iControl Works
iControl 101 - #01 - iControl Marketing Dissected
iC2I: Automation - Creating Virtuals Simplified.
GTM, Know Thyself
Getting Started with pyControl
FTPS Offload via iRules
Exchange Persistence Duality and iRules
Dynamic WSDL updating with iRules
Custom SNMP Traps
Creating An iControl PowerShell Monitoring Dashboard With Google Charts
Cookie LoJack vi iRules
Content-Disposition - Forced file downloads via HTTP
Concurrent iControl Programming Explained
Case Insensitive Comparisons
Can iRules fix my cert mismatch errors?
Cache in with LTM and iRules
Building a Custom WebAccelerator Policy
Automated Web Analytics iRule Style
Investigating the LTM TCP Profile: Max Syn Retransmissions & Idle Timeout