def connect(self, host, userid, password=None, ssh_key_string=None):
_method_ = "MLNXOSPlugin.connect"
self.host = host
self.userid = userid
try:
self.client = paramiko.SSHClient()
self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
if ssh_key_string:
private_key = paramiko.RSAKey.from_private_key(StringIO(ssh_key_string), password)
self.client.connect(host, username=userid, pkey=private_key, timeout=30,
allow_agent=False)
else:
self.client.connect(host, username=userid, password=password, timeout=30,
allow_agent=False)
if not self._is_mellanox_switch():
raise exceptions.InvalidDeviceException(
"Device is not a Mellanox Switch")
except paramiko.AuthenticationException:
logging.error("%s::userid/password combination not valid. host=%s userid=%s",
_method_, host, userid)
raise exceptions.AuthenticationException(
"userid/password combination not valid")
except (paramiko.ssh_exception.SSHException, OSError, socket.timeout) as e:
logging.exception(e)
logging.error("%s::Connection timed out. host=%s", _method_, host)
raise exceptions.ConnectionException("Unable to ssh to the device")
MLNXOSManagerPlugin.py 文件源码
python
阅读 25
收藏 0
点赞 0
评论 0
评论列表
文章目录