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
评论列表
文章目录