host_ctrl.py 文件源码

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

项目:virtapi 作者: spiperac 项目源码 文件源码
def connect(self):
        """
        Returns None in case of failed connection.
        """
        conn = None
        if self.conn_status is False:
            return False


        if self.host_protocol == 'libssh2':
            self.auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_PASSPHRASE], self.request_cred, None]
            if self.host_url == None:
                conn = libvirt.open("qemu:///system")
            else:
                url = "{}://{}/?sshauth=password".format(VIRT_CONN_LIBSSH2, self.host_url)
                conn = libvirt.openAuth(url, self.auth, 0)

        elif self.host_protocol == 'ssh':
            if self.host_url == None:
                conn = libvirt.open("qemu:///system")
            else:
                url = "{}://{}@{}/system?socket=/var/run/libvirt/libvirt-sock&keyfile={}".format(VIRT_CONN_SSH, self.host_username, 
                                                                                                                    self.host_url, 
                                                                                                                    self.host_key)
                conn = libvirt.open(url)

        elif self.host_protocol == 'qemu':
            conn = libvirt.open("qemu:///system")

        if conn == None:
            logging.error('Connection to hypervisor failed!')
            return False
        else:
            logging.info('Connection succesfull.')
            self.conn = conn
            SETTINGS['connection'] = self.conn
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号