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