[libvirt-users] python equiv to perl list_domains()

From our machine that will be running the script RHEL 5.9 yum list | grep libvirt
conn.listAllDomains(1)
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 libvirt.x86_64 0.8.2-29.el5_9.1 libvirt-python.x86_64 0.8.2-29.el5_9.1 from the dom0 RHEL 5.9 yum list | grep xen xen.x86_64 3.0.3-142.el5_9.2 xen-libs.i386 3.0.3-142.el5_9.2 xen-libs.x86_64 3.0.3-142.el5_9.2 yum list | grep libvirt libvirt.i386 0.8.2-29.el5_9.1 installed libvirt.x86_64 0.8.2-29.el5_9.1 installed This is the error if I try to do listAllDomains from a FC18 box libvir: Remote Driver error : unknown procedure: 273 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib64/python2.7/site-packages/libvirt.py", line 3695, in listAllDomains raise libvirtError("virConnectListAllDomains() failed", conn=self) libvirt.libvirtError: unknown procedure: 273

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.
conn.listAllDomains(1)
This is the error if I try to do listAllDomains from a FC18 box 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
participants (2)
-
Brett Y
-
Eric Blake