RhelManagerPlugin.py 文件源码

python
阅读 50 收藏 0 点赞 0 评论 0

项目:opsmgr 作者: open-power-ref-design-toolkit 项目源码 文件源码
def connect(self, host, userid, password=None, ssh_key_string=None):
        _method_ = "RhelPlugin.connect"
        self.userid = userid
        self.password = password
        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_guest_rhel():
                raise exceptions.InvalidDeviceException(
                    "Device is not a RHEL Device")
        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")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号