的paramiko exec_command,超时工作不

问题描述:

设置:1.15.1的paramiko 根据超时是为exec_command因为1.10.0,但由于某种原因,它不是为我工作创建的文档。我的代码中有错误,我错过了或者它实际上是一个错误?的paramiko exec_command,超时工作不

我有这样的代码

class CustomSSH(object): 

    def __init__(self, node): 
     self.node = node 
     self.ssh = paramiko.SSHClient() 
     self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 
     try: 
      self.privkey = paramiko.RSAKey.from_private_key_file('./secret.key') 
     except: 
      self.use_password = True 

    def connect_ssh(self, timeout=60): 
     try: 
      if self.use_password: 
       self.ssh.connect(self.node, 
           timeout=60, 
           username='xxx', 
           password='xxx', 
           look_for_keys=False) 
      else: 
       """Using SSH Key""" 
       self.ssh.connect(self.node, 
           timeout=60, 
           username='xxx', 
           pkey=self.privkey, 
           look_for_keys=False) 
      self.using_ssh = True 
      return True 

     except paramiko.AuthenticationException, e: 
      if self.use_password: 
       raise paramiko.SSHException 
      print "Private key {}".format(e) 
      print "Trying using username/password instead" 
      self.use_password = True 
      self.connect_ssh() 

     except paramiko.SSHException, e: 
      print "some other error ", e 
      self.close() 
      raise 
     except Exception: 
      print "exception" 
      raise 

    def close(self): 
     print "Closing connection" 
     try: 
      self.ssh.close() 
     except: 
      print "Error closing connection" 

    def send_cmd(self, command, regexmatch='', timeout=60): 
     """Issue Commands using SSH 
      returns a Tuple of (True/False, results)""" 
     try: 
      stdin, stdout, stderr = self.ssh.exec_command(command, timeout) 
      xresults = stdout.readlines() 
      results = ''.join(xresults) 
      re_status = re.compile(regexmatch, re.IGNORECASE) 
      if re_status.search(results): 
       return (True, xresults) 
      else: 
       return (False, xresults) 
     except Exception as e: 
      raise KeyError, e 

那我执行如下:

ssh = CustomSSH(node) 
ssh.connect_ssh() 
ssh.send_cmd(abort_cmd) 

这里有什么问题?

那是当然是一个简单的拼写错误。

当调用exec_command我发送超时代替超时=值的值。

self.ssh.exec_command(command, timeout) 

应该已经

self.ssh.exec_command(command, timeout=60)