|
@@ -1,3 +1,4 @@
|
|
|
+import errno
|
|
|
import sys
|
|
|
import telnetlib
|
|
|
import time
|
|
@@ -37,27 +38,31 @@ class ObjectTelnet(ObjectConnection):
|
|
|
print("Lock Acquire\n")
|
|
|
print("Login in...\n")
|
|
|
self.tn = telnetlib.Telnet(self.hostname, self.port)
|
|
|
- # self.tn.set_debuglevel(1)
|
|
|
- self.read_data([self.olt.get_expected_name()])
|
|
|
- self.tn.write(self.user + self.NEW_LINE_UNIX)
|
|
|
- self.read_data([self.olt.get_expected_password()])
|
|
|
- self.tn.write(self.password + self.NEW_LINE_UNIX)
|
|
|
- print("Loged in...\n")
|
|
|
- print self.tn.read_very_lazy()
|
|
|
- self.read_data([self.olt.get_expected_initial()])
|
|
|
- if self.file_name is not None:
|
|
|
- self.connection_file()
|
|
|
- elif self.data is not None:
|
|
|
- self.connection_data()
|
|
|
- else:
|
|
|
- self.connection_old()
|
|
|
- print("fin-----")
|
|
|
- while self.QUIT:
|
|
|
- # send quit to terminal until exit confirmation
|
|
|
- self.command_quit(self.olt.get_write_exit())
|
|
|
- self.tn.close()
|
|
|
- self.save_log()
|
|
|
- exit(self.RUN_OK)
|
|
|
+ self.tn.set_debuglevel(1)
|
|
|
+ error = self.read_data([self.olt.get_expected_name()])
|
|
|
+ if error != -1:
|
|
|
+ self.tn.write(self.user + self.NEW_LINE_UNIX)
|
|
|
+ error = self.read_data([self.olt.get_expected_password()])
|
|
|
+ if error != -1:
|
|
|
+ self.tn.write(self.password + self.NEW_LINE_UNIX)
|
|
|
+ print("Loged in...\n")
|
|
|
+ print self.tn.read_very_lazy()
|
|
|
+ error = self.read_data([self.olt.get_expected_initial()])
|
|
|
+ if error != -1:
|
|
|
+ if self.file_name is not None:
|
|
|
+ self.connection_file()
|
|
|
+ elif self.data is not None:
|
|
|
+ self.connection_data()
|
|
|
+ else:
|
|
|
+ self.connection_old()
|
|
|
+ print("fin-----")
|
|
|
+ while self.QUIT:
|
|
|
+ # send quit to terminal until exit confirmation
|
|
|
+ self.command_quit(self.olt.get_write_exit())
|
|
|
+ self.tn.close()
|
|
|
+ self.save_log()
|
|
|
+ exit(self.RUN_OK)
|
|
|
+ exit(self.RUN_ERROR)
|
|
|
|
|
|
def connection_old(self):
|
|
|
"""
|
|
@@ -111,21 +116,26 @@ class ObjectTelnet(ObjectConnection):
|
|
|
:return: Return True if enable otherwise False
|
|
|
"""
|
|
|
if command.lower() == self.olt.get_write_exit().lower():
|
|
|
- self.tn.write(self.olt.get_write_exit() + self.NEW_LINE_UNIX)
|
|
|
- read_data = None
|
|
|
- with_confirmation = False
|
|
|
- if self.olt.get_expected_exit() is not None:
|
|
|
- read_data = [self.olt.get_expected_cardinal(), self.olt.get_expected_exit()]
|
|
|
- with_confirmation = True
|
|
|
- if self.olt.get_expected_exit_with_confirmation() is not None:
|
|
|
- read_data = [self.olt.get_expected_cardinal(), self.olt.get_expected_exit_with_confirmation()]
|
|
|
+ try:
|
|
|
+ self.tn.write(self.olt.get_write_exit() + self.NEW_LINE_UNIX)
|
|
|
+ read_data = None
|
|
|
with_confirmation = False
|
|
|
- if read_data is not None:
|
|
|
- position = self.read_data(read_data)
|
|
|
- if position == 2:
|
|
|
- # quit terminal
|
|
|
- if with_confirmation:
|
|
|
- self.tn.write(self.olt.get_write_exit_confirmation() + self.NEW_LINE_UNIX)
|
|
|
+ if self.olt.get_expected_exit() is not None:
|
|
|
+ read_data = [self.olt.get_expected_cardinal(), self.olt.get_expected_exit()]
|
|
|
+ with_confirmation = True
|
|
|
+ if self.olt.get_expected_exit_with_confirmation() is not None:
|
|
|
+ read_data = [self.olt.get_expected_cardinal(), self.olt.get_expected_exit_with_confirmation()]
|
|
|
+ with_confirmation = False
|
|
|
+ if read_data is not None:
|
|
|
+ position = self.read_data(read_data)
|
|
|
+ if position == 2:
|
|
|
+ # quit terminal
|
|
|
+ if with_confirmation:
|
|
|
+ self.tn.write(self.olt.get_write_exit_confirmation() + self.NEW_LINE_UNIX)
|
|
|
+ self.QUIT = False
|
|
|
+ # except self.tn.error, e:
|
|
|
+ except IOError, e:
|
|
|
+ if e.errno == errno.EPIPE:
|
|
|
self.QUIT = False
|
|
|
return True
|
|
|
return False
|
|
@@ -150,14 +160,20 @@ class ObjectTelnet(ObjectConnection):
|
|
|
Read channel waiting parameter character
|
|
|
:param expected: List of expected string
|
|
|
"""
|
|
|
- position = 1
|
|
|
- (i, obj, all_data) = self.tn.expect(expected, 10)
|
|
|
- nc = 1
|
|
|
- for ch in expected:
|
|
|
- if ch in all_data:
|
|
|
- position = nc
|
|
|
- break
|
|
|
- nc += 1
|
|
|
- print(str(all_data))
|
|
|
- self.all_data = self.all_data + str(all_data)
|
|
|
+ iteration = 0
|
|
|
+ position = -1
|
|
|
+ while iteration < 6:
|
|
|
+ (i, obj, all_data) = self.tn.expect(expected, 10)
|
|
|
+ nc = 1
|
|
|
+ for ch in expected:
|
|
|
+ if ch in all_data:
|
|
|
+ position = nc
|
|
|
+ break
|
|
|
+ nc += 1
|
|
|
+ if position == -1:
|
|
|
+ iteration += 1
|
|
|
+ else:
|
|
|
+ iteration = 6
|
|
|
+ print(str(all_data))
|
|
|
+ self.all_data = self.all_data + str(all_data)
|
|
|
return position
|