python libvirt api openAuth()

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python libvirt api openAuth()相关的知识,希望对你有一定的参考价值。

使用tcp连接libvirt服务,不适用密码

/etc/libvirt/libvirtd.conf 
auth_tcp="none"
service libvirtd restart
import libvirt
conn = libvirt.open("qemu+tcp://localhost/system")
print conn.getHostname()

使用tcp加密码连接libvirt

auth_tcp="sasl"
saslpasswd2 -a libvirt admin
sasldblistusers2 -f /etc/libvirt/passwd.db
service libvirtd restart

连接代码

import libvirt
USER = "root"
PASSWD = "mypasswd"

def authcb(credentials, user_data):
   for credential in credentials:
       if credential[0] == libvirt.VIR_CRED_AUTHNAME:
           credential[4] = USER
       elif credential[0] == libvirt.VIR_CRED_PASSPHRASE:
           credential[4] = PASSWD
   return 0

auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_PASSPHRASE], authcb, None]
conn = libvirt.openAuth("qemu+ssh://localhost/system", auth, 0)

print conn.getHostname()

参考文档:

  http://blog.csdn.net/gaoxingnengjisuan/article/details/9674315

  http://blog.csdn.net/qq_21398167/article/details/46422583


以上是关于python libvirt api openAuth()的主要内容,如果未能解决你的问题,请参考以下文章

如何通过python创建kvm虚拟机

(转)libvirt API的基本概念

libvirt 部分API 介绍

(转)libvirt 部分API 介绍

libvirt API - 覆盖,背景图像

libvirt API非阻塞调用及相关的原理分析