__init__.py 文件源码

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

项目:worker 作者: mechaphish 项目源码 文件源码
def _initialize_ssh_connection(self):
        LOG.debug("Connecting to the VM via SSH")
        self.ssh = paramiko.client.SSHClient()

        self.ssh.set_missing_host_key_policy(paramiko.client.AutoAddPolicy())
        try:
            self.ssh.connect("127.0.0.1", port=self._ssh_port, username=self._ssh_username,
                             key_filename=self._ssh_keyfile, timeout=self._ssh_timeout)
            # Set TCP Keep-Alive to 5 seconds, so that the connection does not die
            transport = self.ssh.get_transport()
            transport.set_keepalive(5)
            # also raises BadHostKeyException, should be taken care of via AutoAddPolicy()
            # also raises AuthenticationException, should never occur because keys are provisioned
        except socket.error as e:
            LOG.error("TCP error connecting to SSH on VM.")
            raise e
        except paramiko.SSHException as e:
            LOG.error("SSH error trying to connect to VM.")
            raise e
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号