Skip to content

Instantly share code, notes, and snippets.

@brainix
Created October 15, 2015 06:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brainix/7d964d1e2d038d7f0d62 to your computer and use it in GitHub Desktop.
Save brainix/7d964d1e2d038d7f0d62 to your computer and use it in GitHub Desktop.
# XXX -- Top level review comments:
#
# * Nice exception recovery and logging.
#
# * Please cleanup code formatting.
# This is a little rough on my eyes.
#
# * Should we use this as template for other
# short network element scripts?
#
# -- Thanks. The Boss :-)
import jnettool.tools.elements.NetworkElement, \
jnettool.tools.Routing, \
jnettool.tools.RouteInspector
ne=jnettool.tools.elements.NetworkElement( '171.0.2.45' )
try:
routing_table=ne.getRoutingTable() # fetch table
except jnettool.tools.elements.MissingVar:
# Record table fault
logging.exception( '''No routing table found''' )
# Undo partial changes
ne.cleanup( '''rollback''' )
else:
num_routes=routing_table.getSize() # determine table size
for RToffset in range( num_routes ):
route=routing_table.getRouteByIndex( RToffset )
name=route.getName() # route name
ipaddr=route.getIPAddr() # ip address
print "%15s -> %s"% (name,ipaddr) # format nicely
finally:
ne.cleanup( '''commit''' ) # lockin changes
ne.disconnect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment