|
@@ -17,6 +17,7 @@ class ObjectSsh(ObjectConnection):
|
|
ObjectConnection.__init__(self)
|
|
ObjectConnection.__init__(self)
|
|
self.stdin = None
|
|
self.stdin = None
|
|
self.stdout = None
|
|
self.stdout = None
|
|
|
|
+ self.debug = False
|
|
|
|
|
|
def connect(self):
|
|
def connect(self):
|
|
"""
|
|
"""
|
|
@@ -41,6 +42,7 @@ class ObjectSsh(ObjectConnection):
|
|
self.stdin = chan.makefile('wb')
|
|
self.stdin = chan.makefile('wb')
|
|
self.stdout = chan.makefile('r')
|
|
self.stdout = chan.makefile('r')
|
|
# wait to olt to initialice terminal
|
|
# wait to olt to initialice terminal
|
|
|
|
+ print ("Logged in")
|
|
self.read_data(self.olt.get_expected_initial())
|
|
self.read_data(self.olt.get_expected_initial())
|
|
if self.file_name is not None:
|
|
if self.file_name is not None:
|
|
self.connection_file()
|
|
self.connection_file()
|
|
@@ -65,9 +67,15 @@ class ObjectSsh(ObjectConnection):
|
|
"""
|
|
"""
|
|
if command.lower() == self.olt.get_write_enable().lower():
|
|
if command.lower() == self.olt.get_write_enable().lower():
|
|
if self.olt.run_enable():
|
|
if self.olt.run_enable():
|
|
|
|
+ if self.debug:
|
|
|
|
+ print "Send: "
|
|
|
|
+ print self.olt.get_write_enable()
|
|
self.stdin.write(self.olt.get_write_enable() + self.NEW_LINE_UNIX)
|
|
self.stdin.write(self.olt.get_write_enable() + self.NEW_LINE_UNIX)
|
|
if self.olt.run_enable_password():
|
|
if self.olt.run_enable_password():
|
|
self.read_data(self.olt.get_expected_enable_password())
|
|
self.read_data(self.olt.get_expected_enable_password())
|
|
|
|
+ if self.debug:
|
|
|
|
+ print "Send: "
|
|
|
|
+ print self.password_enable
|
|
self.stdin.write(self.password_enable + self.NEW_LINE_UNIX)
|
|
self.stdin.write(self.password_enable + self.NEW_LINE_UNIX)
|
|
self.read_data(self.olt.get_expected_cardinal())
|
|
self.read_data(self.olt.get_expected_cardinal())
|
|
return True
|
|
return True
|
|
@@ -81,10 +89,16 @@ class ObjectSsh(ObjectConnection):
|
|
"""
|
|
"""
|
|
if command.lower() == self.olt.get_write_exit().lower():
|
|
if command.lower() == self.olt.get_write_exit().lower():
|
|
try:
|
|
try:
|
|
|
|
+ if self.debug:
|
|
|
|
+ print "Send: "
|
|
|
|
+ print self.olt.get_write_exit()
|
|
self.stdin.write(self.olt.get_write_exit() + self.NEW_LINE_UNIX)
|
|
self.stdin.write(self.olt.get_write_exit() + self.NEW_LINE_UNIX)
|
|
position = self.read_data([self.olt.get_expected_cardinal(), self.olt.get_expected_exit()])
|
|
position = self.read_data([self.olt.get_expected_cardinal(), self.olt.get_expected_exit()])
|
|
if position == 2:
|
|
if position == 2:
|
|
# quit terminal
|
|
# quit terminal
|
|
|
|
+ if self.debug:
|
|
|
|
+ print "Send: "
|
|
|
|
+ print self.olt.get_write_exit_confirmation()
|
|
self.stdin.write(self.olt.get_write_exit_confirmation() + self.NEW_LINE_UNIX)
|
|
self.stdin.write(self.olt.get_write_exit_confirmation() + self.NEW_LINE_UNIX)
|
|
self.stdin.flush()
|
|
self.stdin.flush()
|
|
self.QUIT = False
|
|
self.QUIT = False
|
|
@@ -102,9 +116,12 @@ class ObjectSsh(ObjectConnection):
|
|
:param expected: Expected string to stop listening
|
|
:param expected: Expected string to stop listening
|
|
"""
|
|
"""
|
|
self.command_print(command)
|
|
self.command_print(command)
|
|
|
|
+ command = command.rstrip(self.NEW_LINE_WINDOWS).rstrip(self.NEW_LINE_UNIX)
|
|
if not self.command_enable(command) and not self.command_quit(command):
|
|
if not self.command_enable(command) and not self.command_quit(command):
|
|
- command = command.rstrip(self.NEW_LINE_WINDOWS).rstrip(self.NEW_LINE_UNIX)
|
|
|
|
if command.__len__() > 0:
|
|
if command.__len__() > 0:
|
|
|
|
+ if self.debug:
|
|
|
|
+ print "Send: "
|
|
|
|
+ print command
|
|
self.stdin.write(command + self.NEW_LINE_UNIX)
|
|
self.stdin.write(command + self.NEW_LINE_UNIX)
|
|
self.stdin.flush()
|
|
self.stdin.flush()
|
|
self.read_data(expected)
|
|
self.read_data(expected)
|
|
@@ -120,10 +137,18 @@ class ObjectSsh(ObjectConnection):
|
|
position = 1
|
|
position = 1
|
|
if isinstance(character, types.StringType):
|
|
if isinstance(character, types.StringType):
|
|
character = [character]
|
|
character = [character]
|
|
|
|
+ if self.debug:
|
|
|
|
+ print "Expected: "
|
|
|
|
+ print character
|
|
|
|
+ print "Recived:"
|
|
while not self.stdout.channel.exit_status_ready() and not stop:
|
|
while not self.stdout.channel.exit_status_ready() and not stop:
|
|
all_data += self.stdout.channel.recv(buffer_size)
|
|
all_data += self.stdout.channel.recv(buffer_size)
|
|
|
|
+ if self.debug:
|
|
|
|
+ print all_data
|
|
while self.stdout.channel.recv_ready():
|
|
while self.stdout.channel.recv_ready():
|
|
all_data += self.stdout.channel.recv(buffer_size)
|
|
all_data += self.stdout.channel.recv(buffer_size)
|
|
|
|
+ if self.debug:
|
|
|
|
+ print all_data
|
|
nc = 1
|
|
nc = 1
|
|
for ch in character:
|
|
for ch in character:
|
|
if ch in all_data:
|
|
if ch in all_data:
|