Created
October 15, 2015 06:12
-
-
Save brainix/7d964d1e2d038d7f0d62 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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