[Netdevicelib-checkins] CVS: netdevicelib/src/netdevicelib connections.py,1.3,1.4 devices.py,1.1.1.1
Status: Alpha
Brought to you by:
bluecoat93
|
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:
|