Demo entry 6631645

pip

   

Submitted by anonymous on Jul 18, 2017 at 10:13
Language: Python. Code size: 1.2 kB.

class Linux:

    def __init__(self,filename):
        self.logger = logger_manager.LoggerManager().get_logger(filename)
        self.ip = upload_config.IP
        self.username = upload_config.USERNAME
        self.password = upload_config.PASSWORD
        self.timeout = upload_config.TIMEOUT
        self.try_times = upload_config.TRY_TIMES
        self.t = ""
        self.chan = ""


    def connect(self):
        while True:
            try:
                self.t = paramiko.Transport(sock=(self.ip, 22))
                self.t.connect(username=self.username, password=self.password)
                self.chan = self.t.open_session()
                self.chan.settimeout(self.timeout)
                self.chan.get_pty()
                self.chan.invoke_shell()
                print "SSH connect success"
                self.logger.debug("SSH connect success\r")
                return
            except Exception, e:
                 if self.try_times != 0:
                     self.logger.debug( '连接%s失败,进行重试' %self.ip)
                     self.try_times -= 1
                 else:
                     self.logger.debug( '重试3次失败,结束程序')
                     exit(1)

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).