本文整理汇总了Python中paramiko.BadAuthenticationType方法的典型用法代码示例。如果您正苦于以下问题:Python paramiko.BadAuthenticationType方法的具体用法?Python paramiko.BadAuthenticationType怎么用?Python paramiko.BadAuthenticationType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类paramiko
的用法示例。
在下文中一共展示了paramiko.BadAuthenticationType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ssh_connect
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import BadAuthenticationType [as 别名]
def ssh_connect(self):
ssh = paramiko.SSHClient()
ssh._system_host_keys = self.settings['system_host_keys']
ssh._host_keys = self.settings['host_keys']
ssh.set_missing_host_key_policy(self.settings['policy'])
args = self.get_args()
dst_addr = (args[0], args[1])
logging.info('Connecting to {}:{}'.format(*dst_addr))
try:
ssh.connect(*args, timeout=6)
except socket.error:
raise ValueError('Unable to connect to {}:{}'.format(*dst_addr))
except paramiko.BadAuthenticationType:
raise ValueError('Authentication failed.')
except paramiko.BadHostKeyException:
raise ValueError('Bad host key.')
chan = ssh.invoke_shell(term='xterm')
chan.setblocking(0)
worker = Worker(ssh, chan, dst_addr)
IOLoop.current().call_later(DELAY, recycle, worker)
return worker
示例2: ssh_connect
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import BadAuthenticationType [as 别名]
def ssh_connect(self, args):
ssh = self.ssh_client
dst_addr = args[:2]
logging.info('Connecting to {}:{}'.format(*dst_addr))
try:
ssh.connect(*args, timeout=options.timeout)
except socket.error:
raise ValueError('Unable to connect to {}:{}'.format(*dst_addr))
except paramiko.BadAuthenticationType:
raise ValueError('Bad authentication type.')
except paramiko.AuthenticationException:
raise ValueError('Authentication failed.')
except paramiko.BadHostKeyException:
raise ValueError('Bad host key.')
term = self.get_argument('term', u'') or u'xterm'
chan = ssh.invoke_shell(term=term)
chan.setblocking(0)
worker = Worker(self.loop, ssh, chan, dst_addr)
worker.encoding = options.encoding if options.encoding else \
self.get_default_encoding(ssh)
return worker
示例3: ssh_connect
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import BadAuthenticationType [as 别名]
def ssh_connect(self):
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
args = self.get_args()
dst_addr = '{}:{}'.format(*args[:2])
logging.info('Connecting to {}'.format(dst_addr))
try:
ssh.connect(*args, timeout=6)
except socket.error:
raise ValueError('Unable to connect to {}'.format(dst_addr))
except paramiko.BadAuthenticationType:
raise ValueError('Authentication failed.')
chan = ssh.invoke_shell(term='xterm')
chan.setblocking(0)
worker = Worker(ssh, chan, dst_addr)
IOLoop.current().call_later(DELAY, recycle, worker)
return worker
示例4: ssh_connect
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import BadAuthenticationType [as 别名]
def ssh_connect(self):
ssh = self.ssh_client
try:
args = self.get_args()
except InvalidValueError as exc:
raise tornado.web.HTTPError(400, str(exc))
dst_addr = (args[0], args[1])
logging.info('Connecting to {}:{}'.format(*dst_addr))
try:
ssh.connect(*args, timeout=6)
except socket.error:
raise ValueError('Unable to connect to {}:{}'.format(*dst_addr))
except paramiko.BadAuthenticationType:
raise ValueError('Bad authentication type.')
except paramiko.AuthenticationException:
raise ValueError('Authentication failed.')
except paramiko.BadHostKeyException:
raise ValueError('Bad host key.')
chan = ssh.invoke_shell(term='xterm')
chan.setblocking(0)
worker = Worker(self.loop, ssh, chan, dst_addr, self.src_addr)
worker.encoding = self.get_default_encoding(ssh)
return worker
示例5: get_ssh_client
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import BadAuthenticationType [as 别名]
def get_ssh_client(hostname, ssh_hostname):
"""Tries to create ssh client
Create ssh client based on the username and ssh key
"""
if not CREDS.SSH_KEYFILE:
logger.errorout("ssh_keyfile not set",
module=COMMAND_MODULE_CUSTOM)
retries = 0
while retries < MAX_SSH_RETRIES:
try:
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname=ssh_hostname,
username=CREDS.SSH_USER,
port=CREDS.SSH_PORT,
pkey=CREDS.PK,
timeout=CONNECTION_TIMEOUT)
return ssh
except paramiko.BadAuthenticationType:
logger.error("BadAuthenticationType",
hostname=hostname,
module=COMMAND_MODULE_CUSTOM)
return
except paramiko.AuthenticationException:
logger.error("Authentication failed",
hostname=hostname,
module=COMMAND_MODULE_CUSTOM)
return
except paramiko.BadHostKeyException:
logger.error("BadHostKeyException",
fix="Edit known_hosts file to remove the entry",
hostname=hostname,
module=COMMAND_MODULE_CUSTOM)
return
except paramiko.SSHException:
logger.error("SSHException",
hostname=hostname,
module=COMMAND_MODULE_CUSTOM)
return
except Exception as e:
if retries == 0:
logger.error("Problems connecting to host",
hostname=hostname,
module=COMMAND_MODULE_CUSTOM,
error=e.message)
retries += 1
time.sleep(1)
logger.error("Can not connect to host",
hostname=hostname,
module=COMMAND_MODULE_CUSTOM)
return None