使用libvirt进行远程管理(带身份认证),getdominfo.py
python getdominfo.py xen+tcp://192.168.103.10:16509/
代码如下:
#!/usr/bin/python
import sys, getpass, libvirt
import pdb
#pdb.set_trace()
uri = sys.argv[1]
mydata = ""
def getCredentials(credentials, data):
for credential in credentials:
print credential[1] + ":",
if credential[0] == libvirt.VIR_CRED_AUTHNAME:
data = sys.stdin.readline()
data = data[0:len(data)-1]
credential[4] = data
elif credential[0] == libvirt.VIR_CRED_PASSPHRASE:
credential[4] = getpass.getpass("")
else:
return -1
return 0
flags = [libvirt.VIR_CRED_AUTHNAME,libvirt.VIR_CRED_PASSPHRASE]
auth = [flags,getCredentials,mydata]
#localconn = libvirt.open(None)
#dom = localconn.lookupByName(vmname)
conn = libvirt.openAuth(uri,auth,0)
#dom.migrate(remoteconn,libvirt.VIR_MIGRATE_LIVE,None,uri,0)
for id in conn.listDomainsID():
dom = conn.lookupByID(id)
state = dom.info()
print "Dom %s State %s,mem:%s,3:%s,vCPUs:%s,5:%s" % ( dom.name(), state[0],state[1],state[2],state[3],state[4])
阅读(1032) | 评论(0) | 转发(0) |