1
設置: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)
這裏有什麼問題?