Connect to a libvirt machine and get information on domains
How can you connect to a libvirt host machine and get information on domains
First configure libvirtd:
/etc/libvirtd/libvirtd.conf:
listen_tls=1
listen_tcp=0
tls_no_verify_certificate=0
tls_no_verify_certificate=0
Create certificates for libvirtd and put the client ones in /etc/pki/libvirt as described on the http://libvirt.org/remote.html:"libvirtd website".
Restart libvirtd and there you go.
The following skript helps:
import sys
import libvirt
uri=sys.argv[1]
conn=libvirt.openReadOnly(uri)
for i in conn.listDomainsID():
dom=conn.lookupByID(i)
info=dom.info()
print "Dom %s, state: %u, maxMemory: %u, memory: %u, nbVirtCPU: %u, cpuTime: %u" %(dom.name(), info[0], info[1], info[2], info[3], info[4])
Descripton of info:
- unsigned char state : the running state, one of virDomainFlags
- unsigned long maxMem : the maximum memory in KBytes allowed
- unsigned long memory : the memory in KBytes used by the domain
- unsigned short nrVirtCpu : the number of virtual CPUs for the domain
- unsigned long long cpuTime : the CPU time used in nanoseconds
On URIs:
You might want to use the no_verify=1 parameter if certs cannot be verified. Given vmhost1 as xen virtualized hostname the url would be: xen://xenhost1/?no_verify=1