1、远程执行命令
def remote_execution_command(ip,user,passwd,cmd,Ifsource,loginname=None,get_pty=False):
print_log('INFO','ip : %s,user : %s, cmd : %s start\n' %(ip, user, cmd))
#创建SSH对象
ssh = paramiko.SSHClient()
# 允许连接不在know_hosts文件中的主机
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# 连接服务器
try:
ssh.connect(hostname=ip, port=22, username=user, password=passwd)
except paramiko.ssh_exception.BadHostKeyException as e:
msg = "the server's host key could not be verified. host: %s" % ip
return (1, '', msg)
except paramiko.ssh_exception.AuthenticationException as e:
msg = 'authentication failed. host: %s' % ip
return