netdevicelib-checkins Mailing List for netdevicelib
Status: Alpha
Brought to you by:
bluecoat93
You can subscribe to this list here.
| 2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(10) |
Sep
(2) |
Oct
(3) |
Nov
|
Dec
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(11) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <net...@li...> - 2002-06-19 22:59:44
|
Update of /cvsroot/netdevicelib/netdevicelib/src/netdevicelib
In directory usw-pr-cvs1:/tmp/cvs-serv20749/src/netdevicelib
Modified Files:
connections.py devices.py
Log Message:
- add documentation strings to modules
- add version check to require Python 2.0
- implement distutils setup.py script
Index: connections.py
===================================================================
RCS file: /cvsroot/netdevicelib/netdevicelib/src/netdevicelib/connections.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** connections.py 24 Oct 2001 18:41:58 -0000 1.10
--- connections.py 19 Jun 2002 22:59:40 -0000 1.11
***************
*** 10,18 ****
# ========================================================================
from netdevicelib.devices import DeviceFactory
- import getopt, re, sys, telnetlib, types
# ------------------------------------------------------------------------
LoginFailedException = "Login failed. Bad username or password"
EnableFailedException = "Enable failed. Access denied"
--- 10,30 ----
# ========================================================================
+ import getopt, re, string, sys, telnetlib, types
+
+ # We requre Python 2.0
+ pyversion = string.split( string.split( sys.version )[0], "." )
+
+ if map( int, pyversion ) < [2, 0, 0]:
+ sys.stderr.write( "Sorry, this library requires at least Python 2.0\n" )
+ sys.exit(1);
+
from netdevicelib.devices import DeviceFactory
# ------------------------------------------------------------------------
+ # Module documentation strings
+ __version__ = '$Revision$'.split()[-2]
+
+ # Exceptions
LoginFailedException = "Login failed. Bad username or password"
EnableFailedException = "Enable failed. Access denied"
Index: devices.py
===================================================================
RCS file: /cvsroot/netdevicelib/netdevicelib/src/netdevicelib/devices.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** devices.py 24 Oct 2001 18:42:57 -0000 1.5
--- devices.py 19 Jun 2002 22:59:41 -0000 1.6
***************
*** 10,13 ****
--- 10,29 ----
# ========================================================================
+ import string, sys
+
+ # We requre Python 2.0
+ pyversion = string.split( string.split( sys.version )[0], "." )
+
+ if map( int, pyversion ) < [2, 0, 0]:
+ sys.stderr.write( "Sorry, this library requires at least Python 2.0\n" )
+ sys.exit(1);
+
+ # ------------------------------------------------------------------------
+
+ # Module documentation strings
+ __version__ = '$Revision$'.split()[-2]
+
+ # ------------------------------------------------------------------------
+
class Device:
def __init__( self ):
|
|
From: <net...@li...> - 2002-06-19 22:59:43
|
Update of /cvsroot/netdevicelib/netdevicelib
In directory usw-pr-cvs1:/tmp/cvs-serv20749
Added Files:
.cvsignore MANIFEST.in setup.py
Log Message:
- add documentation strings to modules
- add version check to require Python 2.0
- implement distutils setup.py script
--- NEW FILE: .cvsignore ---
MANIFEST
*.pyc
*.swp
--- NEW FILE: MANIFEST.in ---
include *.txt
--- NEW FILE: setup.py ---
#!/usr/bin/env python
import string, sys
from distutils.core import setup
myVersion = "$Revision: 1.1 $";
# We requre Python 2.0
pyversion = string.split( string.split( sys.version )[0], "." )
if map( int, pyversion ) < [2, 0, 0]:
sys.stderr.write( "Sorry, this library requires at least Python 2.0\n" )
sys.exit(1);
# Call the distutils setup function to install ourselves
setup ( name = "netdevicelib",
version = myVersion.split()[-2],
description = "Python Networking Device library",
author = "Brian Landers",
author_email = "br...@pa...",
url = "http://netdevicelib.sourceforge.net",
package_dir = { '': 'src' },
packages = [ 'netdevicelib' ]
)
|
|
From: <net...@li...> - 2002-06-19 22:54:57
|
Update of /cvsroot/netdevicelib/netdevicelib/build In directory usw-pr-cvs1:/tmp/cvs-serv19733 Added Files: .cvsignore Log Message: - add cvsignore file for build --- NEW FILE: .cvsignore --- * |
|
From: <net...@li...> - 2002-06-19 22:54:31
|
Update of /cvsroot/netdevicelib/netdevicelib/build In directory usw-pr-cvs1:/tmp/cvs-serv19660/build Log Message: Directory /cvsroot/netdevicelib/netdevicelib/build added to the repository |
|
From: <net...@li...> - 2002-06-19 22:51:56
|
Update of /cvsroot/netdevicelib/netdevicelib/dist In directory usw-pr-cvs1:/tmp/cvs-serv18955 Added Files: .cvsignore Log Message: - add cvsignore file for dist directory --- NEW FILE: .cvsignore --- * |
|
From: <net...@li...> - 2002-06-19 22:51:27
|
Update of /cvsroot/netdevicelib/netdevicelib/dist In directory usw-pr-cvs1:/tmp/cvs-serv18881/dist Log Message: Directory /cvsroot/netdevicelib/netdevicelib/dist added to the repository |
|
From: <net...@li...> - 2002-06-15 04:23:09
|
Update of /cvsroot/netdevicelib/netdevicelib/site
In directory usw-pr-cvs1:/tmp/cvs-serv20352
Modified Files:
index.html
Log Message:
- change my email address
Index: index.html
===================================================================
RCS file: /cvsroot/netdevicelib/netdevicelib/site/index.html,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** index.html 15 Jun 2002 04:13:16 -0000 1.4
--- index.html 15 Jun 2002 04:23:07 -0000 1.5
***************
*** 35,39 ****
<p><i>netdevicelib</i> was written by <a
! href="http://www.bluecoat93.org">Brian Landers<a>. See the <A
HREF="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/netdevicelib/netdevicelib/CREDITS.txt?rev=HEAD&content-type=text/vnd.viewcvs-markup">CREDITS.txt</A>
file in the distribution for more information on contributors.</p>
--- 35,39 ----
<p><i>netdevicelib</i> was written by <a
! href="http://www.packetslave.com">Brian Landers<a>. See the <A
HREF="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/netdevicelib/netdevicelib/CREDITS.txt?rev=HEAD&content-type=text/vnd.viewcvs-markup">CREDITS.txt</A>
file in the distribution for more information on contributors.</p>
***************
*** 44,51 ****
<hr>
! <address><a href="mailto:br...@bl...">Brian Landers</a></address>
<!-- Created: Sun Aug 26 13:32:56 EDT 2001 -->
<!-- hhmts start -->
! Last modified: Sat Jun 15 00:13:08 EDT 2002
<!-- hhmts end -->
</body>
--- 44,51 ----
<hr>
! <address><a href="mailto:br...@pa...">Brian Landers</a></address>
<!-- Created: Sun Aug 26 13:32:56 EDT 2001 -->
<!-- hhmts start -->
! Last modified: Sat Jun 15 00:23:03 EDT 2002
<!-- hhmts end -->
</body>
|
|
From: <net...@li...> - 2002-06-15 04:14:17
|
Update of /cvsroot/netdevicelib/netdevicelib In directory usw-pr-cvs1:/tmp/cvs-serv19278 Modified Files: INSTALL.txt Log Message: - updated for 0.1 Index: INSTALL.txt =================================================================== RCS file: /cvsroot/netdevicelib/netdevicelib/INSTALL.txt,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** INSTALL.txt 14 Aug 2001 18:29:35 -0000 1.1 --- INSTALL.txt 15 Jun 2002 04:14:15 -0000 1.2 *************** *** 1 **** ! Stub INSTALL file for the netdevicelib project \ No newline at end of file --- 1,2 ---- ! Simply copy the src/netdevicelib directory somewhere into your PYTHONPATH ! (more detailed instructions and a distutils installer on the to-do list) \ No newline at end of file |
|
From: <net...@li...> - 2002-06-15 04:13:18
|
Update of /cvsroot/netdevicelib/netdevicelib/site
In directory usw-pr-cvs1:/tmp/cvs-serv19195
Modified Files:
index.html
Log Message:
- updated for 0.1 release
Index: index.html
===================================================================
RCS file: /cvsroot/netdevicelib/netdevicelib/site/index.html,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** index.html 26 Aug 2001 19:37:12 -0000 1.3
--- index.html 15 Jun 2002 04:13:16 -0000 1.4
***************
*** 21,35 ****
<p><b>How do I get it?</b></p>
! <p><i>netdevicelib</i> is currently in a pre-alpha stage, and as
! such has no formal release available. The adventurous may access
! the current source tree via <A
! HREF="http://sourceforge.net/cvs/?group_id=33586">anonymous
! CVS</A>. You may also browse the CVS tree on SourceForge using
! the
! <A HREF="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/netdevicelib/">
! viewcvs</A> tool.</p>
!
! <p>For more information on the current status of the project,
! please see the <a
href="http://www.sourceforge.net/projects/netdevicelib">Project
Page</A>.
--- 21,25 ----
<p><b>How do I get it?</b></p>
! <p>Releases may be downloaded from the <a
href="http://www.sourceforge.net/projects/netdevicelib">Project
Page</A>.
***************
*** 40,45 ****
HREF="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/netdevicelib/netdevicelib/src/netdevicelib/examples/">examples</A>
directory in the distribution for an example of
! usage. Documentation is definitely on the to-do list for the first
! alpha release.</p>
<p><b>Who wrote it?</b></p>
--- 30,34 ----
HREF="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/netdevicelib/netdevicelib/src/netdevicelib/examples/">examples</A>
directory in the distribution for an example of
! usage. Documentation is definitely on the to-do list.</p>
<p><b>Who wrote it?</b></p>
***************
*** 47,51 ****
<p><i>netdevicelib</i> was written by <a
href="http://www.bluecoat93.org">Brian Landers<a>. See the <A
! HREF="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/netdevicelib/netdevicelib/CREDITS.txt?rev=HEAD&content-type=text/vnd.viewcvs-markup">Credits.txt</A>
file in the distribution for more information on contributors.</p>
--- 36,40 ----
<p><i>netdevicelib</i> was written by <a
href="http://www.bluecoat93.org">Brian Landers<a>. See the <A
! HREF="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/netdevicelib/netdevicelib/CREDITS.txt?rev=HEAD&content-type=text/vnd.viewcvs-markup">CREDITS.txt</A>
file in the distribution for more information on contributors.</p>
***************
*** 58,62 ****
<!-- Created: Sun Aug 26 13:32:56 EDT 2001 -->
<!-- hhmts start -->
! Last modified: Sun Aug 26 14:23:32 EDT 2001
<!-- hhmts end -->
</body>
--- 47,51 ----
<!-- Created: Sun Aug 26 13:32:56 EDT 2001 -->
<!-- hhmts start -->
! Last modified: Sat Jun 15 00:13:08 EDT 2002
<!-- hhmts end -->
</body>
|
|
From: <net...@li...> - 2002-06-15 04:10:55
|
Update of /cvsroot/netdevicelib/netdevicelib In directory usw-pr-cvs1:/tmp/cvs-serv18912 Modified Files: CHANGES.txt Log Message: - 0.1 release Index: CHANGES.txt =================================================================== RCS file: /cvsroot/netdevicelib/netdevicelib/CHANGES.txt,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CHANGES.txt 14 Aug 2001 18:29:35 -0000 1.1 --- CHANGES.txt 15 Jun 2002 04:10:52 -0000 1.2 *************** *** 1 **** ! Stub CHANGES file for the netdevicelib project \ No newline at end of file --- 1,2 ---- ! ! 0.1 06/15/2002 - Initial release \ No newline at end of file |
|
From: <net...@li...> - 2002-06-15 04:10:32
|
Update of /cvsroot/netdevicelib/netdevicelib In directory usw-pr-cvs1:/tmp/cvs-serv18878 Modified Files: README.txt Log Message: - wrote the first version Index: README.txt =================================================================== RCS file: /cvsroot/netdevicelib/netdevicelib/README.txt,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** README.txt 14 Aug 2001 18:29:35 -0000 1.1 --- README.txt 15 Jun 2002 04:10:29 -0000 1.2 *************** *** 1 **** ! Stub README file for the netdevicelib project \ No newline at end of file --- 1,31 ---- ! netdevicelib 0.1 ! Brian Landers <br...@pa...> ! 06/15/2002 ! ! netdevicelib is a Python package providing an API for access to ! network devices such as Cisco routers and switches. It allows easy ! access to devices for the purpose of configuration, command execution, ! and other tasks. It is modelled after the Net::Telnet::Cisco module ! for Perl, but is designed to be extensible to multiple vendors and ! multiple types of connections (ssh, serial, etc.) ! ! Usage: ! ! from netdevicelib.connections import ConnectionFactory ! ! conn = ConnectionFactory().createConnection( "telnet", "IOS" ) ! conn.open( router1.example.com ) ! conn.login( "myusername", "mypassword" ); ! ! lines = conn.cmd( "show version" ) ! print lines ! ! Notes: ! ! Right now, netdevicelib is in a very preliminary state, and most ! likely makes a lot of assumptions about the devices to which it is ! connecting. This is due to the limited number of devices ! available for testing. Feedback is most welcome and suggestions ! for improvement are encouraged. If it doesn't work with your ! device, please provide whatever information you can to help fix ! the problem. |
|
From: <net...@li...> - 2001-10-24 18:43:00
|
Update of /cvsroot/netdevicelib/netdevicelib/src/netdevicelib
In directory usw-pr-cvs1:/tmp/cvs-serv19452
Modified Files:
devices.py
Log Message:
- refactor common prompts and commands to the Device base class
- implement the PixOS device subclass
- tweak the regexps to handle both Pix and IOS (removed leading \n)
Index: devices.py
===================================================================
RCS file: /cvsroot/netdevicelib/netdevicelib/src/netdevicelib/devices.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** devices.py 2001/09/05 18:07:22 1.4
--- devices.py 2001/10/24 18:42:57 1.5
***************
*** 29,32 ****
--- 29,42 ----
'enabledIndicator': ''}
+ # These are the default commands and prompts
+ self.setCommand( 'enable', 'enable' )
+ self.setCommand( 'disable', 'disable' )
+ self.setPrompt( 'login', '[Ll]ogin[:\s]*$' )
+ self.setPrompt( 'username', '[Uu]sername[:\s]*$' )
+ self.setPrompt( 'password', '[Pp]assw(?:or)?d[:\s]*$' )
+ self.setPrompt( 'command', '[\w().-]*[\$#>]\s?(?:\(enable\))?\s*$' )
+ self.setPrompt( 'enable', '[Pp]assword[:\s]*$' )
+ self.setPrompt( 'enabledIndicator', '\#|enable' )
+
def getPrompt( self, inKey=None ):
""" Get the RE to match a given prompt on the device """
***************
*** 75,88 ****
self.setCommand( 'enablePaging', 'terminal length 24' )
self.setCommand( 'getConfig', 'show running-config' )
- self.setCommand( 'enable', 'enable' )
- self.setCommand( 'disable', 'disable' )
- self.setPrompt( 'login', '[Ll]ogin[:\s]*$' )
- self.setPrompt( 'username', '[Uu]sername[:\s]*$' )
- self.setPrompt( 'password', '[Pp]assw(?:or)?d[:\s]*$' )
- self.setPrompt( 'command', '\n[\w().-]*[\$#>]\s?(?:\(enable\))?\s*$' )
- self.setPrompt( 'enable', '[Pp]assword[:\s]*$' )
- self.setPrompt( 'enabledIndicator', '\#|enable' )
-
class CatOSDevice( Device ):
def __init__( self ):
--- 85,89 ----
***************
*** 96,101 ****
self.setCommand( 'enablePaging', 'set length 24' )
self.setCommand( 'getConfig', 'write term' )
- self.setCommand( 'enable', 'enable' )
- self.setCommand( 'disable', 'disable' )
class PixDevice( Device ):
--- 97,100 ----
***************
*** 107,116 ****
self._needsEnable = 1
! self.setCommand( 'disablePagingCmd', 'no pager' )
! self.setCommand( 'enablePagingCmd', 'pager' )
! self.setCommand( 'getConfig', 'write term' )
! self.setCommand( 'enable', 'enable' )
! self.setCommand( 'disable', 'disable' )
!
class DeviceFactory:
def createDevice( self, inClass=None ):
--- 106,113 ----
self._needsEnable = 1
! self.setCommand( 'disablePaging', 'no pager' )
! self.setCommand( 'enablePaging', 'pager' )
! self.setCommand( 'getConfig', 'write term' )
!
class DeviceFactory:
def createDevice( self, inClass=None ):
|
|
From: <net...@li...> - 2001-10-24 18:42:01
|
Update of /cvsroot/netdevicelib/netdevicelib/src/netdevicelib
In directory usw-pr-cvs1:/tmp/cvs-serv19181
Modified Files:
connections.py
Log Message:
- add the ability to pass the device type to the __main__ test code
Index: connections.py
===================================================================
RCS file: /cvsroot/netdevicelib/netdevicelib/src/netdevicelib/connections.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** connections.py 2001/10/04 18:12:33 1.9
--- connections.py 2001/10/24 18:41:58 1.10
***************
*** 141,145 ****
result = self._conn.expect( matches, self._timeout )
! self._debuglog( "Found username prompt" )
# Unless we only got a password prompt, send the username
--- 141,149 ----
result = self._conn.expect( matches, self._timeout )
! self._debuglog( "Found username prompt, match %s" % result[0] )
!
! # If we didn't find a match, bail out
! if result[0] == -1:
! raise RuntimeError( "Didn't find a login prompt" )
# Unless we only got a password prompt, send the username
***************
*** 286,296 ****
# Make sure they entered all the parameters we need
! if len( args ) < 4:
print "usage: connections.py " + \
! "hostname username password [enable] command"
sys.exit(1)
# Create the connection object
! conn = ConnectionFactory().createConnection( "telnet", "IOS" )
# Set the debugging flag if the user indicated debugging
--- 290,300 ----
# Make sure they entered all the parameters we need
! if len( args ) < 5:
print "usage: connections.py " + \
! "hostname type username password [enable] command"
sys.exit(1)
# Create the connection object
! conn = ConnectionFactory().createConnection( "telnet", args[1] )
# Set the debugging flag if the user indicated debugging
***************
*** 300,311 ****
# Open the connection and login
conn.open( args[0] )
! conn.login( args[1], args[2] )
# If the user provided an enable password, go into enable mode
if len( args ) == 6:
! conn.enable( args[3] )
! cmd = args[4]
else:
! cmd = args[3]
# Run the command and print the output
--- 304,315 ----
# Open the connection and login
conn.open( args[0] )
! conn.login( args[2], args[3] )
# If the user provided an enable password, go into enable mode
if len( args ) == 6:
! conn.enable( args[4] )
! cmd = args[5]
else:
! cmd = args[4]
# Run the command and print the output
|
|
From: <net...@li...> - 2001-10-04 18:12:36
|
Update of /cvsroot/netdevicelib/netdevicelib/src/netdevicelib
In directory usw-pr-cvs1:/tmp/cvs-serv24315/src/netdevicelib
Modified Files:
connections.py
Log Message:
- move debug logging into the Connection class -- debug() and _debuglog()
- add command-line processing to the __main__ test driver
Index: connections.py
===================================================================
RCS file: /cvsroot/netdevicelib/netdevicelib/src/netdevicelib/connections.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** connections.py 2001/09/07 01:37:13 1.8
--- connections.py 2001/10/04 18:12:33 1.9
***************
*** 11,17 ****
from netdevicelib.devices import DeviceFactory
! import re, sys, telnetlib, types
!
! DEBUGGING=0
# ------------------------------------------------------------------------
--- 11,15 ----
from netdevicelib.devices import DeviceFactory
! import getopt, re, sys, telnetlib, types
# ------------------------------------------------------------------------
***************
*** 29,37 ****
""" Constructor """
assert inDevice != None
!
! self._device = inDevice
! self._timeout = inTimeout
! self._isOpen = 0
! self._lastPrompt = ''
# Virtual methods -- must be overridden
--- 27,36 ----
""" Constructor """
assert inDevice != None
!
! self._device = inDevice
! self._timeout = inTimeout
! self._isDebugging = 0;
! self._isOpen = 0
! self._lastPrompt = ''
# Virtual methods -- must be overridden
***************
*** 53,56 ****
--- 52,69 ----
# Base class methods -- may be overridden
+ def _debuglog( self, inMessage="No Message" ):
+ """ Write a debug message to STDERR if debugging is enabled """
+
+ if self.debug():
+ sys.stderr.write( "DEBUG: %s\n" % inMessage )
+
+ def debug( self, inLevel=None ):
+ """ Accessor method for the debugging flag """
+
+ if inLevel != None:
+ self._isDebugging = inLevel
+
+ return self._isDebugging
+
def isEnabled( self ):
""" Returns true if the connection is in 'superuser' mode """
***************
*** 102,106 ****
self._conn.open( inHost )
self._isOpen = 1
! debug( "Connection open" )
def close( self ):
--- 115,119 ----
self._conn.open( inHost )
self._isOpen = 1
! self._debuglog( "Connection open" )
def close( self ):
***************
*** 123,155 ****
self._device.getPrompt('password') ]
! debug( "Looking for username prompt (" +
! self._device.getPrompt( 'username' ) + ")" )
result = self._conn.expect( matches, self._timeout )
! debug( "Found username prompt" )
# Unless we only got a password prompt, send the username
if result[0] != 2:
# Send the login name
! debug( "Sending username (" + inUser + ")" )
self._conn.write( inUser + "\n" )
# Wait for password prompt
! debug( "Looking for password prompt (" +
! self._device.getPrompt( 'password' ) + ")" )
result = self._conn.expect( [ self._device.getPrompt('password') ],
self._timeout )
! debug( "Found password prompt" )
# Send password
! debug( "Sending password (" + inPass + ")" )
self._conn.write( inPass + "\n" )
# Wait for command prompt or another login prompt
! debug( "Looking for cmd prompt + (" +
! self._device.getPrompt('command') + ")" )
result = self._conn.expect( matches +
--- 136,168 ----
self._device.getPrompt('password') ]
! self._debuglog( "Looking for username prompt (" +
! self._device.getPrompt( 'username' ) + ")" )
result = self._conn.expect( matches, self._timeout )
! self._debuglog( "Found username prompt" )
# Unless we only got a password prompt, send the username
if result[0] != 2:
# Send the login name
! self._debuglog( "Sending username (" + inUser + ")" )
self._conn.write( inUser + "\n" )
# Wait for password prompt
! self._debuglog( "Looking for password prompt (" +
! self._device.getPrompt( 'password' ) + ")" )
result = self._conn.expect( [ self._device.getPrompt('password') ],
self._timeout )
! self._debuglog( "Found password prompt" )
# Send password
! self._debuglog( "Sending password (" + inPass + ")" )
self._conn.write( inPass + "\n" )
# Wait for command prompt or another login prompt
! self._debuglog( "Looking for cmd prompt + (" +
! self._device.getPrompt('command') + ")" )
result = self._conn.expect( matches +
***************
*** 157,161 ****
self._timeout )
! debug( "Found cmd prompt" )
# Bad login if we got another login prompt
--- 170,174 ----
self._timeout )
! self._debuglog( "Found cmd prompt" )
# Bad login if we got another login prompt
***************
*** 163,167 ****
raise LoginFailedException
else:
! debug( "login succeeded" )
# Disable paging so that commands work correctly
--- 176,180 ----
raise LoginFailedException
else:
! self._debuglog( "login succeeded" )
# Disable paging so that commands work correctly
***************
*** 176,180 ****
return ""
! debug( "running command (" + inCmd + ")" )
self._conn.write( inCmd + "\n" )
--- 189,193 ----
return ""
! self._debuglog( "running command (" + inCmd + ")" )
self._conn.write( inCmd + "\n" )
***************
*** 187,191 ****
prompts = [ self._device.getPrompt('command') ]
! debug( "Looking for cmd prompt + (" + str(prompts) + ")" )
result = self._conn.expect( prompts, self._timeout )
--- 200,204 ----
prompts = [ self._device.getPrompt('command') ]
! self._debuglog( "Looking for cmd prompt + (" + str(prompts) + ")" )
result = self._conn.expect( prompts, self._timeout )
***************
*** 206,210 ****
assert inPass != None
! debug( "trying to enable with password %s" % inPass )
# Send the enable command, expecting the password prompt
--- 219,223 ----
assert inPass != None
! self._debuglog( "trying to enable with password %s" % inPass )
# Send the enable command, expecting the password prompt
***************
*** 240,243 ****
--- 253,258 ----
class ConnectionFactory:
+ """ Factory class for creating Connecton sub-class objects """
+
def createConnection( self, inType=None, inClass=None ):
""" Factory method to create Connection sub-class objects """
***************
*** 253,279 ****
raise RuntimeError( "Type '" + inType + "' not supported" )
! # ------------------------------------------------------------------------
- def debug( inMessage="No Message" ):
- if DEBUGGING:
- print 'DEBUG: %s' % inMessage
-
if __name__ == "__main__":
! if len( sys.argv ) < 5:
print "usage: connections.py " + \
"hostname username password [enable] command"
sys.exit(1)
!
conn = ConnectionFactory().createConnection( "telnet", "IOS" )
- conn.open( sys.argv[1] )
- conn.login( sys.argv[2], sys.argv[3] )
! if len( sys.argv ) == 6:
! conn.enable( sys.argv[4] )
! cmd = sys.argv[5]
else:
! cmd = sys.argv[4]
!
lines = conn.cmd( cmd )
print lines
conn.close()
--- 268,316 ----
raise RuntimeError( "Type '" + inType + "' not supported" )
! # ========================================================================
! # Test driver
! # ========================================================================
if __name__ == "__main__":
!
! # Parse our command-line arguments
! debugging = 0
! try:
! opts, args = getopt.getopt( sys.argv[1:], "d", ["debug"] )
! except getopt.GetoptError:
! print "Use -d or --debug for debugging"
! sys.exit(1)
! for o,a in opts:
! if o in ( '-d', '--debug' ):
! debugging = 1
!
! # Make sure they entered all the parameters we need
! if len( args ) < 4:
print "usage: connections.py " + \
"hostname username password [enable] command"
sys.exit(1)
!
! # Create the connection object
conn = ConnectionFactory().createConnection( "telnet", "IOS" )
! # Set the debugging flag if the user indicated debugging
! if debugging:
! conn.debug(1)
!
! # Open the connection and login
! conn.open( args[0] )
! conn.login( args[1], args[2] )
!
! # If the user provided an enable password, go into enable mode
! if len( args ) == 6:
! conn.enable( args[3] )
! cmd = args[4]
else:
! cmd = args[3]
!
! # Run the command and print the output
lines = conn.cmd( cmd )
print lines
+
+ # Finally, close the connection
conn.close()
|
|
From: <net...@li...> - 2001-09-07 01:37:16
|
Update of /cvsroot/netdevicelib/netdevicelib/src/netdevicelib
In directory usw-pr-cvs1:/tmp/cvs-serv26792
Modified Files:
connections.py
Log Message:
- bug #458825: remove command from output returned from cmd()
Index: connections.py
===================================================================
RCS file: /cvsroot/netdevicelib/netdevicelib/src/netdevicelib/connections.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** connections.py 2001/09/05 18:07:22 1.7
--- connections.py 2001/09/07 01:37:13 1.8
***************
*** 193,200 ****
# Store the last prompt we saw
self._lastPrompt = result[1].group()
# Remove the prompt from the output and return the results
exp = re.compile( self._device.getPrompt('command') )
! return exp.sub( '', result[2] )
def enable( self, inPass=None ):
--- 193,204 ----
# Store the last prompt we saw
self._lastPrompt = result[1].group()
+
+ # Remove the command itself from the output
+ exp = re.compile( '^%s\s*$\n' % inCmd, re.MULTILINE )
+ output = exp.sub( '', result[2], 1 )
# Remove the prompt from the output and return the results
exp = re.compile( self._device.getPrompt('command') )
! return exp.sub( '', output )
def enable( self, inPass=None ):
|
|
From: <net...@li...> - 2001-09-05 18:07:25
|
Update of /cvsroot/netdevicelib/netdevicelib/src/netdevicelib
In directory usw-pr-cvs1:/tmp/cvs-serv3203/src/netdevicelib
Modified Files:
connections.py devices.py
Log Message:
- implement TelnetConnection.disable() method
- add 'disable' command attribute to Device and subclass
- add docstrings to TelnetConnection
- tweak testing code in connections.py to allow 'enable'ed commands
- remove destructor in Connection that was causing exceptions
Index: connections.py
===================================================================
RCS file: /cvsroot/netdevicelib/netdevicelib/src/netdevicelib/connections.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** connections.py 2001/08/26 21:31:48 1.6
--- connections.py 2001/09/05 18:07:22 1.7
***************
*** 17,22 ****
# ------------------------------------------------------------------------
! LoginFailedException = "Login failed. Bad username or password"
! EnableFailedException = "Enable failed. Access denied"
# ------------------------------------------------------------------------
--- 17,23 ----
# ------------------------------------------------------------------------
! LoginFailedException = "Login failed. Bad username or password"
! EnableFailedException = "Enable failed. Access denied"
! DisableFailedException = "Disable command failed."
# ------------------------------------------------------------------------
***************
*** 34,41 ****
self._lastPrompt = ''
- def __del__( self ):
- """ Destructor """
- self.close()
-
# Virtual methods -- must be overridden
def open( self, inHost=None, inPort=23 ):
--- 35,38 ----
***************
*** 93,96 ****
--- 90,94 ----
def __init__( self, inDevice=None ):
+ """ Constructor """
assert inDevice != None
***************
*** 99,102 ****
--- 97,101 ----
def open( self, inHost=None, inPort=23 ):
+ """ Open the connection to the device """
assert inHost != None
***************
*** 106,109 ****
--- 105,110 ----
def close( self ):
+ """ Close the connection to the device """
+
if self._isOpen:
self.enablePaging()
***************
*** 113,116 ****
--- 114,118 ----
def login( self, inUser=None, inPass=None ):
+ """ Login to the device using a username and password """
assert inUser != None
assert inPass != None
***************
*** 167,170 ****
--- 169,173 ----
def cmd( self, inCmd=None, inPrompt=None ):
+ """ Run a command on the device and return the output """
assert inCmd != None
***************
*** 196,200 ****
--- 199,205 ----
def enable( self, inPass=None ):
+ """ Put the connection in 'superuser' mode """
assert inPass != None
+
debug( "trying to enable with password %s" % inPass )
***************
*** 211,217 ****
def disable( self ):
! raise RuntimeError( "Disable not yet implemented" )
def isEnabled( self ):
exp = re.compile( self._device.getPrompt( 'enabledIndicator' ) )
if exp.search( self._lastPrompt ) == None:
--- 216,230 ----
def disable( self ):
! """ Take the connection out of 'superuser' mode """
!
! self.cmd( self._device.getCommand('disable') )
+ # Make sure we disabled
+ if self.isEnabled():
+ raise DisableFailedException
+
def isEnabled( self ):
+ """ Returns true if the connection is in 'superuser' mode """
+
exp = re.compile( self._device.getPrompt( 'enabledIndicator' ) )
if exp.search( self._lastPrompt ) == None:
***************
*** 243,248 ****
if __name__ == "__main__":
! if len( sys.argv ) != 5:
! print "usage: connections.py hostname username password command"
sys.exit(1)
--- 256,262 ----
if __name__ == "__main__":
! if len( sys.argv ) < 5:
! print "usage: connections.py " + \
! "hostname username password [enable] command"
sys.exit(1)
***************
*** 251,254 ****
conn.login( sys.argv[2], sys.argv[3] )
! lines = conn.cmd( sys.argv[4] )
print lines
--- 265,275 ----
conn.login( sys.argv[2], sys.argv[3] )
! if len( sys.argv ) == 6:
! conn.enable( sys.argv[4] )
! cmd = sys.argv[5]
! else:
! cmd = sys.argv[4]
!
! lines = conn.cmd( cmd )
print lines
+ conn.close()
Index: devices.py
===================================================================
RCS file: /cvsroot/netdevicelib/netdevicelib/src/netdevicelib/devices.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** devices.py 2001/08/26 21:31:48 1.3
--- devices.py 2001/09/05 18:07:22 1.4
***************
*** 19,23 ****
'enablePaging' : '',
'getConfig' : '',
! 'enable' : '' }
self._prompts = { 'login' : '',
--- 19,24 ----
'enablePaging' : '',
'getConfig' : '',
! 'enable' : '',
! 'disable' : '' }
self._prompts = { 'login' : '',
***************
*** 75,78 ****
--- 76,80 ----
self.setCommand( 'getConfig', 'show running-config' )
self.setCommand( 'enable', 'enable' )
+ self.setCommand( 'disable', 'disable' )
self.setPrompt( 'login', '[Ll]ogin[:\s]*$' )
***************
*** 91,98 ****
self._needsEnable = 1
! self._setCommand( 'disablePaging', 'set length 0' )
! self._setCommand( 'enablePaging', 'set length 24' )
! self._setCommand( 'getConfig', 'write term' )
! self._setCommand( 'enable', 'enable' )
class PixDevice( Device ):
--- 93,101 ----
self._needsEnable = 1
! self.setCommand( 'disablePaging', 'set length 0' )
! self.setCommand( 'enablePaging', 'set length 24' )
! self.setCommand( 'getConfig', 'write term' )
! self.setCommand( 'enable', 'enable' )
! self.setCommand( 'disable', 'disable' )
class PixDevice( Device ):
***************
*** 108,111 ****
--- 111,115 ----
self.setCommand( 'getConfig', 'write term' )
self.setCommand( 'enable', 'enable' )
+ self.setCommand( 'disable', 'disable' )
class DeviceFactory:
|
|
From: <net...@li...> - 2001-08-26 21:31:50
|
Update of /cvsroot/netdevicelib/netdevicelib/src/netdevicelib
In directory usw-pr-cvs1:/tmp/cvs-serv8581/netdevicelib
Modified Files:
connections.py devices.py
Log Message:
* implement TelnetConnection.enable()
* implement TelnetConnection.isEnabled()
* add virtual methods to Connection base class
* Connection destructor now closes the connection
* getConfig.py takes the enable password as a parameter
Index: connections.py
===================================================================
RCS file: /cvsroot/netdevicelib/netdevicelib/src/netdevicelib/connections.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** connections.py 2001/08/26 20:37:24 1.5
--- connections.py 2001/08/26 21:31:48 1.6
***************
*** 11,15 ****
from netdevicelib.devices import DeviceFactory
! import re, sys, telnetlib
DEBUGGING=0
--- 11,15 ----
from netdevicelib.devices import DeviceFactory
! import re, sys, telnetlib, types
DEBUGGING=0
***************
*** 17,21 ****
# ------------------------------------------------------------------------
! LoginFailedException = "Login failed. Bad username or password"
# ------------------------------------------------------------------------
--- 17,22 ----
# ------------------------------------------------------------------------
! LoginFailedException = "Login failed. Bad username or password"
! EnableFailedException = "Enable failed. Access denied"
# ------------------------------------------------------------------------
***************
*** 28,36 ****
assert inDevice != None
! self._device = inDevice
! self._isEnabled = 0
! self._isOpen = 0
! self._timeout = inTimeout
def disablePaging( self ):
""" Helper function to disable screen paging for a connection """
--- 29,75 ----
assert inDevice != None
! self._device = inDevice
! self._timeout = inTimeout
! self._isOpen = 0
! self._lastPrompt = ''
!
! def __del__( self ):
! """ Destructor """
! self.close()
!
! # Virtual methods -- must be overridden
! def open( self, inHost=None, inPort=23 ):
! """ Open the connection to the device """
! raise RuntimeException, "Unimplemented base class method called"
!
! def close( self ):
! """ Close the connection to the device """
! raise RuntimeException, "Unimplemented base class method called"
!
! def login( self, inUser=None, inPass=None ):
! """ Login to the device using a username and password """
! raise RuntimeException, "Unimplemented base class method called"
!
! def cmd( self, inCmd=None, inPrompt=None ):
! """ Run a command on the device and return the output """
! raise RuntimeException, "Unimplemented base class method called"
!
! # Base class methods -- may be overridden
! def isEnabled( self ):
! """ Returns true if the connection is in 'superuser' mode """
! return 1
!
! def enable( self, inPass=None ):
! """ Put the connection in 'superuser' mode """
! pass
!
! def disable( self ):
! """ Take the connection out of 'superuser' mode """
! pass
+ def getLastPrompt( self ):
+ """ Accessor method to get the last prompt we saw """
+ return self._lastPrompt
+
def disablePaging( self ):
""" Helper function to disable screen paging for a connection """
***************
*** 40,47 ****
""" Helper function to enable screen paging for a connection """
self.cmd( self._device.getCommand('enablePaging') )
!
def getConfig( self ):
""" Helper function to get the current config from a connection """
! if self._device._needsEnable and not self._isEnabled:
raise RuntimeError( "You must be enabled first" )
--- 79,86 ----
""" Helper function to enable screen paging for a connection """
self.cmd( self._device.getCommand('enablePaging') )
!
def getConfig( self ):
""" Helper function to get the current config from a connection """
! if self._device._needsEnable and not self.isEnabled():
raise RuntimeError( "You must be enabled first" )
***************
*** 54,58 ****
def __init__( self, inDevice=None ):
- """ Constructor """
assert inDevice != None
--- 93,96 ----
***************
*** 60,69 ****
self._conn = telnetlib.Telnet()
- def __del__( self ):
- """ Destructor - close the connection """
- self.close()
-
def open( self, inHost=None, inPort=23 ):
- """ Open the connection to the device """
assert inHost != None
--- 98,102 ----
***************
*** 73,78 ****
def close( self ):
- """ Close the connection to the device """
-
if self._isOpen:
self.enablePaging()
--- 106,109 ----
***************
*** 82,86 ****
def login( self, inUser=None, inPass=None ):
- """ Login to the device using a username and password """
assert inUser != None
assert inPass != None
--- 113,116 ----
***************
*** 135,150 ****
# Disable paging so that commands work correctly
self.disablePaging()
-
- def enable( self, inPass=None ):
- """ Go into 'superuser' mode on the device """
- assert inPass != None
- raise RuntimeError( "Enable/Disable not yet implemented" )
! def disable( self ):
! """ Get out of superuser mode """
! raise RuntimeError( "Enable/Disable not yet implemented" )
!
! def cmd( self, inCmd=None ):
! """ Run a command on the device and return the output """
assert inCmd != None
--- 165,170 ----
# Disable paging so that commands work correctly
self.disablePaging()
! def cmd( self, inCmd=None, inPrompt=None ):
assert inCmd != None
***************
*** 156,169 ****
self._conn.write( inCmd + "\n" )
! debug( "Looking for cmd prompt + (" +
! self._device.getPrompt('command') + ")" )
!
! result = self._conn.expect( [ self._device.getPrompt('command') ],
! self._timeout )
# Remove the prompt from the output and return the results
exp = re.compile( self._device.getPrompt('command') )
return exp.sub( '', result[2] )
!
# ------------------------------------------------------------------------
--- 176,223 ----
self._conn.write( inCmd + "\n" )
! if inPrompt != None:
! if type( inPrompt ) == types.ListType:
! prompts = inPrompt
! else:
! prompts = [ inPrompt ]
! else:
! prompts = [ self._device.getPrompt('command') ]
!
! debug( "Looking for cmd prompt + (" + str(prompts) + ")" )
+ result = self._conn.expect( prompts, self._timeout )
+
+ # Store the last prompt we saw
+ self._lastPrompt = result[1].group()
+
# Remove the prompt from the output and return the results
exp = re.compile( self._device.getPrompt('command') )
return exp.sub( '', result[2] )
!
! def enable( self, inPass=None ):
! assert inPass != None
! debug( "trying to enable with password %s" % inPass )
!
! # Send the enable command, expecting the password prompt
! self.cmd( self._device.getCommand('enable'),
! self._device.getPrompt('enable') )
!
! # Set the password
! self.cmd( inPass )
!
! # Make sure we got enabled
! if not self.isEnabled():
! raise EnableFailedException
!
! def disable( self ):
! raise RuntimeError( "Disable not yet implemented" )
!
! def isEnabled( self ):
! exp = re.compile( self._device.getPrompt( 'enabledIndicator' ) )
! if exp.search( self._lastPrompt ) == None:
! return 0
! else:
! return 1
!
# ------------------------------------------------------------------------
***************
*** 186,190 ****
def debug( inMessage="No Message" ):
if DEBUGGING:
! print "DEBUG: " + inMessage
if __name__ == "__main__":
--- 240,244 ----
def debug( inMessage="No Message" ):
if DEBUGGING:
! print 'DEBUG: %s' % inMessage
if __name__ == "__main__":
Index: devices.py
===================================================================
RCS file: /cvsroot/netdevicelib/netdevicelib/src/netdevicelib/devices.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** devices.py 2001/08/26 20:21:37 1.2
--- devices.py 2001/08/26 21:31:48 1.3
***************
*** 18,28 ****
self._commands = { 'disablePaging' : '',
'enablePaging' : '',
! 'getConfig' : '' }
! self._prompts = { 'login' : '',
! 'username' : '',
! 'password' : '',
! 'command' : '',
! 'enable' : '' }
def getPrompt( self, inKey=None ):
--- 18,30 ----
self._commands = { 'disablePaging' : '',
'enablePaging' : '',
! 'getConfig' : '',
! 'enable' : '' }
! self._prompts = { 'login' : '',
! 'username' : '',
! 'password' : '',
! 'command' : '',
! 'enable' : '',
! 'enabledIndicator': ''}
def getPrompt( self, inKey=None ):
***************
*** 72,81 ****
self.setCommand( 'enablePaging', 'terminal length 24' )
self.setCommand( 'getConfig', 'show running-config' )
!
self.setPrompt( 'login', '[Ll]ogin[:\s]*$' )
self.setPrompt( 'username', '[Uu]sername[:\s]*$' )
self.setPrompt( 'password', '[Pp]assw(?:or)?d[:\s]*$' )
! self.setPrompt( 'command', '[\w().-]*[\$#>]\s?(?:\(enable\))?\s*$' )
! self.setPrompt( 'enable', '[Pp]assword[:\s]*$' )
class CatOSDevice( Device ):
--- 74,85 ----
self.setCommand( 'enablePaging', 'terminal length 24' )
self.setCommand( 'getConfig', 'show running-config' )
! self.setCommand( 'enable', 'enable' )
!
self.setPrompt( 'login', '[Ll]ogin[:\s]*$' )
self.setPrompt( 'username', '[Uu]sername[:\s]*$' )
self.setPrompt( 'password', '[Pp]assw(?:or)?d[:\s]*$' )
! self.setPrompt( 'command', '\n[\w().-]*[\$#>]\s?(?:\(enable\))?\s*$' )
! self.setPrompt( 'enable', '[Pp]assword[:\s]*$' )
! self.setPrompt( 'enabledIndicator', '\#|enable' )
class CatOSDevice( Device ):
***************
*** 89,93 ****
self._setCommand( 'disablePaging', 'set length 0' )
self._setCommand( 'enablePaging', 'set length 24' )
!
class PixDevice( Device ):
def __init__( self ):
--- 93,99 ----
self._setCommand( 'disablePaging', 'set length 0' )
self._setCommand( 'enablePaging', 'set length 24' )
! self._setCommand( 'getConfig', 'write term' )
! self._setCommand( 'enable', 'enable' )
!
class PixDevice( Device ):
def __init__( self ):
***************
*** 99,104 ****
self.setCommand( 'disablePagingCmd', 'no pager' )
! self.setCommand( 'enablePagingCmd', 'pager' )
!
class DeviceFactory:
def createDevice( self, inClass=None ):
--- 105,112 ----
self.setCommand( 'disablePagingCmd', 'no pager' )
! self.setCommand( 'enablePagingCmd', 'pager' )
! self.setCommand( 'getConfig', 'write term' )
! self.setCommand( 'enable', 'enable' )
!
class DeviceFactory:
def createDevice( self, inClass=None ):
|
|
From: <net...@li...> - 2001-08-26 21:31:50
|
Update of /cvsroot/netdevicelib/netdevicelib/src/netdevicelib/examples
In directory usw-pr-cvs1:/tmp/cvs-serv8581/netdevicelib/examples
Modified Files:
getConfig.py
Log Message:
* implement TelnetConnection.enable()
* implement TelnetConnection.isEnabled()
* add virtual methods to Connection base class
* Connection destructor now closes the connection
* getConfig.py takes the enable password as a parameter
Index: getConfig.py
===================================================================
RCS file: /cvsroot/netdevicelib/netdevicelib/src/netdevicelib/examples/getConfig.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** getConfig.py 2001/08/26 20:36:51 1.1
--- getConfig.py 2001/08/26 21:31:48 1.2
***************
*** 13,18 ****
# Check the command-line arguments
! if len( sys.argv ) < 4:
! print "Usage: version.py device username password"
sys.exit(0)
--- 13,18 ----
# Check the command-line arguments
! if len( sys.argv ) < 5:
! print "Usage: version.py device username password enable-password"
sys.exit(0)
***************
*** 25,28 ****
--- 25,31 ----
# Login to the device. Assumes username/password login (i.e. TACACS)
conn.login( sys.argv[2], sys.argv[3] )
+
+ # Enable
+ conn.enable( sys.argv[4] )
# Run the command on the device
|
|
From: <net...@li...> - 2001-08-26 20:37:26
|
Update of /cvsroot/netdevicelib/netdevicelib/src/netdevicelib
In directory usw-pr-cvs1:/tmp/cvs-serv31747
Modified Files:
connections.py
Log Message:
- remove unused devices() method
- implement Devices.getConfig() helper method to get a device's config
Index: connections.py
===================================================================
RCS file: /cvsroot/netdevicelib/netdevicelib/src/netdevicelib/connections.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** connections.py 2001/08/26 20:21:37 1.4
--- connections.py 2001/08/26 20:37:24 1.5
***************
*** 33,43 ****
self._timeout = inTimeout
- def device( self, inDevice=None ):
- """ Accessor for the device associated with the connection """
-
- if inDevice != None:
- self._device = inDevice
- return self._device
-
def disablePaging( self ):
""" Helper function to disable screen paging for a connection """
--- 33,36 ----
***************
*** 47,51 ****
--- 40,51 ----
""" Helper function to enable screen paging for a connection """
self.cmd( self._device.getCommand('enablePaging') )
+
+ def getConfig( self ):
+ """ Helper function to get the current config from a connection """
+ if self._device._needsEnable and not self._isEnabled:
+ raise RuntimeError( "You must be enabled first" )
+ return self.cmd( self._device.getCommand('getConfig') )
+
# ------------------------------------------------------------------------
***************
*** 79,83 ****
self._conn.close()
! self._isClosed = 0
def login( self, inUser=None, inPass=None ):
--- 79,83 ----
self._conn.close()
! self._isOpen = 0
def login( self, inUser=None, inPass=None ):
***************
*** 149,152 ****
--- 149,156 ----
assert inCmd != None
+ # Handle blank commands (i.e. unimplemented in the Device subclass)
+ if inCmd == "":
+ return ""
+
debug( "running command (" + inCmd + ")" )
self._conn.write( inCmd + "\n" )
|
|
From: <net...@li...> - 2001-08-26 20:36:54
|
Update of /cvsroot/netdevicelib/netdevicelib/src/netdevicelib/examples
In directory usw-pr-cvs1:/tmp/cvs-serv31668
Added Files:
getConfig.py
Log Message:
- add example script to get a Cisco router's running config
--- NEW FILE: getConfig.py ---
#!/usr/local/bin/python
# A simple example that downloads the running-config from a Cisco router.
# Notes:
# - Assumes that netdevicelib is in your PYTHONPATH.
# - Error checking omitted for clarity
# $Id: getConfig.py,v 1.1 2001/08/26 20:36:51 bluecoat93 Exp $
import sys
from netdevicelib.connections import ConnectionFactory
# Check the command-line arguments
if len( sys.argv ) < 4:
print "Usage: version.py device username password"
sys.exit(0)
# Create a Connection object for a telnet connection to an IOS device
conn = ConnectionFactory().createConnection( "telnet", "IOS" )
# Open the connection to the device
conn.open( sys.argv[1] )
# Login to the device. Assumes username/password login (i.e. TACACS)
conn.login( sys.argv[2], sys.argv[3] )
# Run the command on the device
lines = conn.getConfig()
# Print the output
print lines
|
|
From: <net...@li...> - 2001-08-26 20:21:39
|
Update of /cvsroot/netdevicelib/netdevicelib/src/netdevicelib
In directory usw-pr-cvs1:/tmp/cvs-serv28637/src/netdevicelib
Modified Files:
connections.py devices.py
Log Message:
- (API CHANGE) in Device subclasses, access to commands and prompts
now goes through the get/setCommand() and get/setPrompt() accessor
functions instead of dedicated functions for each command/prompt.
Index: connections.py
===================================================================
RCS file: /cvsroot/netdevicelib/netdevicelib/src/netdevicelib/connections.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** connections.py 2001/08/26 19:49:27 1.3
--- connections.py 2001/08/26 20:21:37 1.4
***************
*** 42,50 ****
def disablePaging( self ):
""" Helper function to disable screen paging for a connection """
! self.cmd( self._device.disablePagingCmd() )
def enablePaging( self ):
""" Helper function to enable screen paging for a connection """
! self.cmd( self._device.enablePagingCmd() )
# ------------------------------------------------------------------------
--- 42,50 ----
def disablePaging( self ):
""" Helper function to disable screen paging for a connection """
! self.cmd( self._device.getCommand('disablePaging') )
def enablePaging( self ):
""" Helper function to enable screen paging for a connection """
! self.cmd( self._device.getCommand('enablePaging') )
# ------------------------------------------------------------------------
***************
*** 87,96 ****
# Wait for the login prompt
! matches = [ self._device.loginPrompt(),
! self._device.usernamePrompt(),
! self._device.passwordPrompt() ]
debug( "Looking for username prompt (" +
! self._device.usernamePrompt() + ")" )
result = self._conn.expect( matches, self._timeout )
--- 87,96 ----
# Wait for the login prompt
! matches = [ self._device.getPrompt('login'),
! self._device.getPrompt('username'),
! self._device.getPrompt('password') ]
debug( "Looking for username prompt (" +
! self._device.getPrompt( 'username' ) + ")" )
result = self._conn.expect( matches, self._timeout )
***************
*** 106,112 ****
# Wait for password prompt
debug( "Looking for password prompt (" +
! self._device.passwordPrompt() + ")" )
! result = self._conn.expect( [ self._device.passwordPrompt() ],
self._timeout )
--- 106,112 ----
# Wait for password prompt
debug( "Looking for password prompt (" +
! self._device.getPrompt( 'password' ) + ")" )
! result = self._conn.expect( [ self._device.getPrompt('password') ],
self._timeout )
***************
*** 118,124 ****
# Wait for command prompt or another login prompt
! debug( "Looking for cmd prompt + (" + self._device.cmdPrompt() + ")" )
! result = self._conn.expect( matches + [ self._device.cmdPrompt() ],
self._timeout )
--- 118,126 ----
# Wait for command prompt or another login prompt
! debug( "Looking for cmd prompt + (" +
! self._device.getPrompt('command') + ")" )
! result = self._conn.expect( matches +
! [ self._device.getPrompt('command') ],
self._timeout )
***************
*** 150,160 ****
self._conn.write( inCmd + "\n" )
! debug( "Looking for cmd prompt + (" + self._device.cmdPrompt() + ")" )
! result = self._conn.expect( [ self._device.cmdPrompt() ],
self._timeout )
# Remove the prompt from the output and return the results
! exp = re.compile( self._device.cmdPrompt() )
return exp.sub( '', result[2] )
--- 152,163 ----
self._conn.write( inCmd + "\n" )
! debug( "Looking for cmd prompt + (" +
! self._device.getPrompt('command') + ")" )
! result = self._conn.expect( [ self._device.getPrompt('command') ],
self._timeout )
# Remove the prompt from the output and return the results
! exp = re.compile( self._device.getPrompt('command') )
return exp.sub( '', result[2] )
***************
*** 190,193 ****
conn.login( sys.argv[2], sys.argv[3] )
! lines = foo.cmd( sys.argv[4] )
print lines
--- 193,196 ----
conn.login( sys.argv[2], sys.argv[3] )
! lines = conn.cmd( sys.argv[4] )
print lines
Index: devices.py
===================================================================
RCS file: /cvsroot/netdevicelib/netdevicelib/src/netdevicelib/devices.py,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** devices.py 2001/08/09 02:44:26 1.1.1.1
--- devices.py 2001/08/26 20:21:37 1.2
***************
*** 12,75 ****
class Device:
def __init__( self ):
self._class = "BASE CLASS"
! self._disablePagingCmd = ""
! self._enablePagingCmd = ""
! self._loginPrompt = ""
! self._usernamePrompt = ""
! self._passwordPrompt = ""
! self._userPrompt = ""
self._needsEnable = 1
! self._enablePrompt = ""
! self._enabledPrompt = ""
! def disablePagingCmd( self ):
! return self._disablePagingCmd
! def enablePagingCmd( self ):
! return self._enablePagingCmd
!
! def loginPrompt( self ):
! return self._loginPrompt
! def usernamePrompt( self ):
! return self._usernamePrompt
!
! def passwordPrompt( self ):
! return self._passwordPrompt
! def cmdPrompt( self ):
! return self._cmdPrompt
def needsEnable( self ):
return self._needsEnable
-
- def enablePrompt( self ):
- return self._enablePrompt
class IOSDevice( Device ):
def __init__( self ):
Device.__init__( self )
- self._class = "IOS"
- self._disablePagingCmd = "terminal length 0"
- self._enablePagingCmd = "terminal length 24"
- self._loginPrompt = '[Ll]ogin[:\s]*$'
- self._usernamePrompt = '[Uu]sername[:\s]*$'
- self._passwordPrompt = '[Pp]assw(?:or)?d[:\s]*$'
- self._cmdPrompt = '[\w().-]*[\$#>]\s?(?:\(enable\))?\s*$'
- self._enablePrompt = '[Pp]assword[:\s]*$'
class CatOSDevice( Device ):
def __init__( self ):
Device.__init__( self )
! self._class = "CatOS"
! self._disablePagingCmd = "set length 0"
! self._enablePagingCmd = "set length 24"
class PixDevice( Device ):
def __init__( self ):
Device.__init__( self )
! self._class = "Pix"
! self._disablePagingCmd = "no pager"
! self._enablePagingCmd = "pager"
class DeviceFactory:
--- 12,103 ----
class Device:
def __init__( self ):
+ """ Constructor """
self._class = "BASE CLASS"
!
self._needsEnable = 1
! self._commands = { 'disablePaging' : '',
! 'enablePaging' : '',
! 'getConfig' : '' }
!
! self._prompts = { 'login' : '',
! 'username' : '',
! 'password' : '',
! 'command' : '',
! 'enable' : '' }
!
! def getPrompt( self, inKey=None ):
! """ Get the RE to match a given prompt on the device """
! assert inKey != None
! try:
! return self._prompts[inKey]
! except KeyError:
! return ''
! def setPrompt( self, inKey=None, inValue=None ):
! """ Set the RE to match a given prompt on the device """
! assert inKey != None
! assert inValue != None
! self._prompts[inKey] = inValue
! def getCommand( self, inKey=None ):
! """ Get the command to perform a given function on the device """
! assert inKey != None
!
! try:
! return self._commands[inKey]
! except KeyError:
! return ''
!
! def setCommand( self, inKey=None, inValue=None ):
! """ Set the command to perform a given function on the device """
! assert inKey != None
! assert inValue != None
!
! self._commands[inKey] = inValue
def needsEnable( self ):
return self._needsEnable
class IOSDevice( Device ):
def __init__( self ):
+ """ Constructor"""
Device.__init__( self )
+ self._class = "IOS"
+ self._needsEnable = 1
+
+ self.setCommand( 'disablePaging', 'terminal length 0' )
+ self.setCommand( 'enablePaging', 'terminal length 24' )
+ self.setCommand( 'getConfig', 'show running-config' )
+
+ self.setPrompt( 'login', '[Ll]ogin[:\s]*$' )
+ self.setPrompt( 'username', '[Uu]sername[:\s]*$' )
+ self.setPrompt( 'password', '[Pp]assw(?:or)?d[:\s]*$' )
+ self.setPrompt( 'command', '[\w().-]*[\$#>]\s?(?:\(enable\))?\s*$' )
+ self.setPrompt( 'enable', '[Pp]assword[:\s]*$' )
+
class CatOSDevice( Device ):
def __init__( self ):
+ """ Constructor """
Device.__init__( self )
!
! self._class = "CatOS"
! self._needsEnable = 1
!
! self._setCommand( 'disablePaging', 'set length 0' )
! self._setCommand( 'enablePaging', 'set length 24' )
class PixDevice( Device ):
def __init__( self ):
+ """ Constructor """
Device.__init__( self )
!
! self._class = "Pix"
! self._needsEnable = 1
!
! self.setCommand( 'disablePagingCmd', 'no pager' )
! self.setCommand( 'enablePagingCmd', 'pager' )
class DeviceFactory:
|
|
From: <net...@li...> - 2001-08-26 19:49:30
|
Update of /cvsroot/netdevicelib/netdevicelib/src/netdevicelib
In directory usw-pr-cvs1:/tmp/cvs-serv22191/src/netdevicelib
Modified Files:
connections.py
Log Message:
Bug #455566 - remove prompt from command output
Index: connections.py
===================================================================
RCS file: /cvsroot/netdevicelib/netdevicelib/src/netdevicelib/connections.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** connections.py 2001/08/09 02:53:26 1.2
--- connections.py 2001/08/26 19:49:27 1.3
***************
*** 11,15 ****
from netdevicelib.devices import DeviceFactory
! import sys, telnetlib
DEBUGGING=0
--- 11,15 ----
from netdevicelib.devices import DeviceFactory
! import re, sys, telnetlib
DEBUGGING=0
***************
*** 154,158 ****
result = self._conn.expect( [ self._device.cmdPrompt() ],
self._timeout )
! return result[2]
# ------------------------------------------------------------------------
--- 154,161 ----
result = self._conn.expect( [ self._device.cmdPrompt() ],
self._timeout )
!
! # Remove the prompt from the output and return the results
! exp = re.compile( self._device.cmdPrompt() )
! return exp.sub( '', result[2] )
# ------------------------------------------------------------------------
|
|
From: <net...@li...> - 2001-08-26 19:37:14
|
Update of /cvsroot/netdevicelib/netdevicelib/site
In directory usw-pr-cvs1:/tmp/cvs-serv19544/site
Modified Files:
index.html
Log Message:
- fix credits link on home page
Index: index.html
===================================================================
RCS file: /cvsroot/netdevicelib/netdevicelib/site/index.html,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** index.html 2001/08/26 18:55:21 1.2
--- index.html 2001/08/26 19:37:12 1.3
***************
*** 47,51 ****
<p><i>netdevicelib</i> was written by <a
href="http://www.bluecoat93.org">Brian Landers<a>. See the <A
! HREF="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/netdevicelib/netdevicelib/Credits.txt?rev=HEAD&content-type=text/vnd.viewcvs-markup">Credits.txt</A>
file in the distribution for more information on contributors.</p>
--- 47,51 ----
<p><i>netdevicelib</i> was written by <a
href="http://www.bluecoat93.org">Brian Landers<a>. See the <A
! HREF="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/netdevicelib/netdevicelib/CREDITS.txt?rev=HEAD&content-type=text/vnd.viewcvs-markup">Credits.txt</A>
file in the distribution for more information on contributors.</p>
|
|
From: <net...@li...> - 2001-08-26 18:55:24
|
Update of /cvsroot/netdevicelib/netdevicelib/src/netdevicelib In directory usw-pr-cvs1:/tmp/cvs-serv11310/src/netdevicelib Removed Files: Credits.txt Log Message: - move CREDITS.txt file to top-level directory - add contents of the GNU LGPL to COPYING.txt - add some Sourceforge links to the home page --- Credits.txt DELETED --- |
|
From: <net...@li...> - 2001-08-26 18:55:24
|
Update of /cvsroot/netdevicelib/netdevicelib/site
In directory usw-pr-cvs1:/tmp/cvs-serv11310/site
Modified Files:
index.html
Log Message:
- move CREDITS.txt file to top-level directory
- add contents of the GNU LGPL to COPYING.txt
- add some Sourceforge links to the home page
Index: index.html
===================================================================
RCS file: /cvsroot/netdevicelib/netdevicelib/site/index.html,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** index.html 2001/08/26 18:16:07 1.1
--- index.html 2001/08/26 18:55:21 1.2
***************
*** 28,33 ****
the
<A HREF="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/netdevicelib/">
! viewcvs</A> tool.
<p><b>How do I use it?</b></p>
--- 28,38 ----
the
<A HREF="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/netdevicelib/">
! viewcvs</A> tool.</p>
+ <p>For more information on the current status of the project,
+ please see the <a
+ href="http://www.sourceforge.net/projects/netdevicelib">Project
+ Page</A>.
+
<p><b>How do I use it?</b></p>
***************
*** 42,46 ****
<p><i>netdevicelib</i> was written by <a
href="http://www.bluecoat93.org">Brian Landers<a>. See the <A
! HREF="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/netdevicelib/netdevicelib/CHANGES.txt?rev=HEAD&content-type=text/vnd.viewcvs-markup">Credits.txt</A>
file in the distribution for more information on contributors.</p>
--- 47,51 ----
<p><i>netdevicelib</i> was written by <a
href="http://www.bluecoat93.org">Brian Landers<a>. See the <A
! HREF="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/netdevicelib/netdevicelib/Credits.txt?rev=HEAD&content-type=text/vnd.viewcvs-markup">Credits.txt</A>
file in the distribution for more information on contributors.</p>
***************
*** 53,57 ****
<!-- Created: Sun Aug 26 13:32:56 EDT 2001 -->
<!-- hhmts start -->
! Last modified: Sun Aug 26 14:16:37 EDT 2001
<!-- hhmts end -->
</body>
--- 58,62 ----
<!-- Created: Sun Aug 26 13:32:56 EDT 2001 -->
<!-- hhmts start -->
! Last modified: Sun Aug 26 14:23:32 EDT 2001
<!-- hhmts end -->
</body>
|