On 07/08/2013 05:30 PM, Brett Y wrote:
Hey,
I'm trying to figure out a way to get a list of the running domains on a
dom0. I can get the ID's but I'd prefer the names. We have another script
written in perl, but I'm trying to get some other functionality in python
as well as work on converting it all to python. It looks like perl has a
list_domains() that will, according to the libvirt doc, "Return a list of
all running domains currently known to the VMM". And this works for us, but
I can't get the same thing in python as listAllDomains doesn't work with
the version of libvirt running on RHEL 5.9
>From our machine that will be running the script
RHEL 5.9
yum list | grep libvirt
libvirt.x86_64 0.8.2-29.el5_9.1
libvirt-python.x86_64 0.8.2-29.el5_9.1
There's your problem - your destination libvirtd is too old. Per
http://libvirt.org/hvsupport.html, support for the C function
virConnectListAllDomains() was not added until 0.9.13. Older libvirt
has to piece together the information via virConnectListDomains() and
virConnectListDefinedDomains(), coupled with virDomainLookupByID() and
virDomainLookupByName(), to get to virDomainPtr objects in C.
This is the error if I try to do listAllDomains from a FC18 box
>>> conn.listAllDomains(1)
libvir: Remote Driver error : unknown procedure: 273
Yep, because you are calling a function that the libvirtd on the acting
end does not implement (python's connect.listAllDomains maps to the C
virConnectListAllDomains). You'll have to instead use the older,
lower-level (and potentially racy) functions, connect.listDefinedDomains
(offline) and connect.listDomainsID (online), then do lookups on those
returned lists (connect.lookupByID and connect.lookupByName) to get
those converted to actual virDomain objects. Or upgrade your libvirtd -
we strive to always remain backwards compatible, so the upgrade
shouldn't break anything you already have running, and will give you the
newer more useful API.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library
http://libvirt.org