def connect(self, protocol='telnet', username="", password=""): self.password = password self.username = username self.protocol = self.myDevice.get("protocol") self.output = '' self.execStartTime = '' self.execEndTime = '' self.configStartTime = '' self.configEndTime = '' self.cmdBuffer = '' if username == "": self.username = self.myDevice.get("username") if password == "": self.password = self.myDevice.get("password") platForm = platform.platform() if protocol == 'ssh': if "Linux" in platForm: cmd = "ssh %s@%s" % (self.myDevice.get('username'), self.myDevice.get('ip')) else: #cmd = "ssh -l %s " % (self.myDevice.get('username')) cmd = "%s -ssh %s -l %s -pw %s" % ( self.plink_path, self.myDevice.get('ip'), self.username, self.password) else: if "Linux" in platForm: cmd = "telnet %s %s" % (self.myDevice.get('consoleIp'), self.myDevice.get("port")) else: cmd = "%s -telnet %s -P %s" % (self.plink_path, self.myDevice.get('consoleIp'), self.myDevice.get("port")) print('%s\n' % (cmd)) self.cmd = cmd if "Linux" in platForm: self.connectId = winpexpect.spawn(self.cmd) else: self.connectId = winpexpect.winspawn(self.cmd) self.connectId.logfile_read = dataStructure.myTempFile() timestamp = dataStructure.get_timestamp() try: self.getPrompt() self.flush() except Exception as err: self.logSession(timestamp) print('%s' % err) raise
def connect(self, protocol='ssh'): self.protocol = self.myDevice.get("protocol") self.output = '' self.execStartTime = '' self.execEndTime = '' self.configStartTime = '' self.configEndTime = '' self.cmdBuffer = '' if protocol == 'ssh': import platform platForm = platform.platform() if "Linux" in platForm: cmd = "ssh %s@%s" % (self.myDevice.get('username'), self.myDevice.get('serverIp')) else: #cmd = "ssh -l %s " % (self.myDevice.get('username')) if self.myDevice.get('exePath') != 0: cmd = "%s -ssh %s -l %s -pw %s" % ( self.myDevice.get('exePath'), self.myDevice.get('serverIp'), self.myDevice.get("username"), self.myDevice.get("password")) else: cmd = "plink.exe -ssh %s -l %s -pw %s" % ( self.myDevice.get('serverIp'), self.myDevice.get("username"), self.myDevice.get("password")) else: cmd = "telnet " cmd = cmd + self.myDevice.get('serverIp') print('%s\n' % (cmd)) self.cmd = cmd if "Linux" in platForm: self.connectId = winpexpect.spawn(self.cmd) else: self.connectId = winpexpect.winspawn(self.cmd) self.connectId.logfile_read = dataStructure.myTempFile() try: self.getPrompt() self.flush() except Exception as err: print('%s' % err) raise
def connect(self, protocol='telnet', username="", password=""): self.password = password self.username = username self.protocol = self.myDevice.get("protocol") self.output = '' self.execStartTime = '' self.execEndTime = '' self.configStartTime = '' self.configEndTime = '' self.cmdBuffer = '' if username == "": self.username = self.myDevice.get("username") if password == "": self.password = self.myDevice.get("password") platForm = platform.platform() if protocol == 'ssh': if "Linux" in platForm: cmd = "ssh %s@%s" %(self.myDevice.get('username'), self.myDevice.get('ip')) else: #cmd = "ssh -l %s " % (self.myDevice.get('username')) cmd = "%s -ssh %s -l %s -pw %s" %(self.plink_path, self.myDevice.get('ip'), self.username, self.password) else: if "Linux" in platForm: cmd = "telnet %s %s" %(self.myDevice.get('consoleIp'), self.myDevice.get("port")) else: cmd = "%s -telnet %s -P %s" % (self.plink_path, self.myDevice.get('consoleIp'), self.myDevice.get("port")) print('%s\n' %(cmd)) self.cmd = cmd if "Linux" in platForm: self.connectId = winpexpect.spawn(self.cmd) else: self.connectId = winpexpect.winspawn(self.cmd) self.connectId.logfile_read = dataStructure.myTempFile() timestamp = dataStructure.get_timestamp() try: self.getPrompt() self.flush() except Exception as err: self.logSession(timestamp) print('%s' %err) raise
def connect(self, protocol='ssh'): self.protocol = self.myDevice.get("protocol") self.output = '' self.execStartTime = '' self.execEndTime = '' self.configStartTime = '' self.configEndTime = '' self.cmdBuffer = '' if protocol == 'ssh': import platform platForm = platform.platform() if "Linux" in platForm: cmd = "ssh %s@%s" %(self.myDevice.get('username'), self.myDevice.get('serverIp')) else: #cmd = "ssh -l %s " % (self.myDevice.get('username')) if self.myDevice.get('exePath') != 0: cmd = "%s -ssh %s -l %s -pw %s" %(self.myDevice.get('exePath'), self.myDevice.get('serverIp'), self.myDevice.get("username"), self.myDevice.get("password")) else: cmd = "plink.exe -ssh %s -l %s -pw %s" % (self.myDevice.get('serverIp'), self.myDevice.get("username"), self.myDevice.get("password")) else: cmd = "telnet " cmd = cmd + self.myDevice.get('serverIp') print('%s\n' %(cmd)) self.cmd = cmd if "Linux" in platForm: self.connectId = winpexpect.spawn(self.cmd) else: self.connectId = winpexpect.winspawn(self.cmd) self.connectId.logfile_read = dataStructure.myTempFile() try: self.getPrompt() self.flush() except Exception as err: print('%s' %err) raise