[libvirt] Python listDefinedDomains broken?

Hi everyone, please, don't roast me if I'm asking stupid things or fail to provide info, since I'm a freshman, using libvirt. I have two servers, both running the following versions: Compiled against library: libvirt 1.3.1 Using library: libvirt 1.3.1 Using API: QEMU 1.3.1 Running hypervisor: QEMU 0.14.0 I'm trying to create a Python program, which gets a list of all defined domains for each host and give a list for domains only defined on one of these hosts. This Python script is running on a third host (my workstation), using these versions: Python: 3.5.1 libvirt-python: 1.3.1 When I'm running virsh on my workstation (version 1.3.1), like this: virsh -c "qemu+ssh://root@host1/system?keyfile=/home/user/.ssh/id_rsa_libvirt" --readonly list --all Then a domain named "winxp_ausgeschaltet" is within that list: Id Name State ---------------------------------------------------- ... - winxp_ausgeschaltet shut off When I do the same for the second host, it is also in that list: Id Name State ---------------------------------------------------- ... 7 winxp_ausgeschaltet running When I do the following in Python, this domain is listed for the first host (where it's state is "shut off"), but not for the second one: import libvirt import sys class kvmhost: def __init__(self, host, keyfile): self.conn = self.connect_kvm(host, keyfile) self.doms = sorted(self.get_doms()) def connect_kvm(self, host, keyfile): try: conn = libvirt.openReadOnly('qemu+ssh://root@' + host + '/system?keyfile=' + keyfile) except libvirt.libvirtError as lve: print('Error: ' + str(lve)) sys.exit(1) return conn def get_doms(self): try: alldoms = self.conn.listDefinedDomains() except libvirt.libvirtError as lve: print('Error: ' + str(lve)) self.conn.close() sys.exit(1) return alldoms host1 = kvmhost('host1', '/path/to/ssh_keyfile') host2 = kvmhost('host2', '/path/to/ssh_keyfile') print(host1.doms) print(host2.doms) What am I doing wrong here or: is there a missbehavior in libvirt or the python module? Using listAllDomains instead of listDefinedDomains gives: libvirt: Remote Driver error : unknown procedure: 273 What is the difference between listAllDomains and listDefinedDomains at all? Thanks for your help. Marc

On Wed, Jun 01, 2016 at 02:49:26PM +0200, Marc Richter wrote:
Hi everyone,
please, don't roast me if I'm asking stupid things or fail to provide info, since I'm a freshman, using libvirt.
No problem, we're a friendly lot here :-)
Then a domain named "winxp_ausgeschaltet" is within that list:
Id Name State ---------------------------------------------------- ... - winxp_ausgeschaltet shut off
When I do the same for the second host, it is also in that list:
Id Name State ---------------------------------------------------- ... 7 winxp_ausgeschaltet running
When I do the following in Python, this domain is listed for the first host (where it's state is "shut off"), but not for the second one:
import libvirt import sys
class kvmhost: def __init__(self, host, keyfile): self.conn = self.connect_kvm(host, keyfile) self.doms = sorted(self.get_doms()) def connect_kvm(self, host, keyfile): try: conn = libvirt.openReadOnly('qemu+ssh://root@' + host + '/system?keyfile=' + keyfile) except libvirt.libvirtError as lve: print('Error: ' + str(lve)) sys.exit(1) return conn def get_doms(self): try: alldoms = self.conn.listDefinedDomains() except libvirt.libvirtError as lve: print('Error: ' + str(lve)) self.conn.close() sys.exit(1) return alldoms
host1 = kvmhost('host1', '/path/to/ssh_keyfile') host2 = kvmhost('host2', '/path/to/ssh_keyfile')
print(host1.doms) print(host2.doms)
What am I doing wrong here or: is there a missbehavior in libvirt or the python module?
This is expected behaviour of the listDefinedDomains() API call - though admittedly somewhat stupid behaviour. Originally libvirt has a listDomainsIDs API call that only listed guests that were running. We then added listDefinedDomains() call that only listed guests that were *not* running. So to get a complete list of guests on the host you had to use *both* listDomainsIDs and listDefinedDomains(). This had a built-in race condition if a guest started or stopped in betweeen the 2 API calls. So we introduced 'listAllDomains' as a better API that can give you a list of *all* domains whether running or stopped.
Using listAllDomains instead of listDefinedDomains gives:
libvirt: Remote Driver error : unknown procedure: 273
I'm really surprised to see that error - this API call has existed since libvirt 0.9.13 and you say you have 1.3.1 which is more than new enough
What is the difference between listAllDomains and listDefinedDomains at all?
Essentially listAllDomains() is what any app using modern libvirt should be using. We recommend ignoring listDefinedDomains & listDomainIDs unless you need to work with older (ancient) libvirt Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Wed, Jun 01, 2016 at 02:03:17PM +0100, Daniel P. Berrange wrote:
On Wed, Jun 01, 2016 at 02:49:26PM +0200, Marc Richter wrote:
Hi everyone,
please, don't roast me if I'm asking stupid things or fail to provide info, since I'm a freshman, using libvirt.
No problem, we're a friendly lot here :-)
Then a domain named "winxp_ausgeschaltet" is within that list:
Id Name State ---------------------------------------------------- ... - winxp_ausgeschaltet shut off
When I do the same for the second host, it is also in that list:
Id Name State ---------------------------------------------------- ... 7 winxp_ausgeschaltet running
When I do the following in Python, this domain is listed for the first host (where it's state is "shut off"), but not for the second one:
import libvirt import sys
class kvmhost: def __init__(self, host, keyfile): self.conn = self.connect_kvm(host, keyfile) self.doms = sorted(self.get_doms()) def connect_kvm(self, host, keyfile): try: conn = libvirt.openReadOnly('qemu+ssh://root@' + host + '/system?keyfile=' + keyfile) except libvirt.libvirtError as lve: print('Error: ' + str(lve)) sys.exit(1) return conn def get_doms(self): try: alldoms = self.conn.listDefinedDomains() except libvirt.libvirtError as lve: print('Error: ' + str(lve)) self.conn.close() sys.exit(1) return alldoms
host1 = kvmhost('host1', '/path/to/ssh_keyfile') host2 = kvmhost('host2', '/path/to/ssh_keyfile')
print(host1.doms) print(host2.doms)
What am I doing wrong here or: is there a missbehavior in libvirt or the python module?
This is expected behaviour of the listDefinedDomains() API call - though admittedly somewhat stupid behaviour.
Originally libvirt has a listDomainsIDs API call that only listed guests that were running.
We then added listDefinedDomains() call that only listed guests that were *not* running.
So to get a complete list of guests on the host you had to use *both* listDomainsIDs and listDefinedDomains().
This had a built-in race condition if a guest started or stopped in betweeen the 2 API calls. So we introduced 'listAllDomains' as a better API that can give you a list of *all* domains whether running or stopped.
Using listAllDomains instead of listDefinedDomains gives:
libvirt: Remote Driver error : unknown procedure: 273
I'm really surprised to see that error - this API call has existed since libvirt 0.9.13 and you say you have 1.3.1 which is more than new enough
I thing that the version of libvirt on the workstation is 1.3.1 but both servers seems to have pretty old system. The qemu version is 0.14.0. If we consider for example Fedora, qemu-0.14.0 was released in Fedora 15 where libvirt version is 0.8.8. That would explain the error message, that both servers has ancient version of OSes. Pavel
What is the difference between listAllDomains and listDefinedDomains at all?
Essentially listAllDomains() is what any app using modern libvirt should be using. We recommend ignoring listDefinedDomains & listDomainIDs unless you need to work with older (ancient) libvirt
Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

Hi Daniel, thanks for that nice answer! Am 01.06.2016 um 15:03 schrieb Daniel P. Berrange:
On Wed, Jun 01, 2016 at 02:49:26PM +0200, Marc Richter wrote:
Hi everyone,
please, don't roast me if I'm asking stupid things or fail to provide info, since I'm a freshman, using libvirt. No problem, we're a friendly lot here :-)
Then a domain named "winxp_ausgeschaltet" is within that list:
Id Name State ---------------------------------------------------- ... - winxp_ausgeschaltet shut off
When I do the same for the second host, it is also in that list:
Id Name State ---------------------------------------------------- ... 7 winxp_ausgeschaltet running
When I do the following in Python, this domain is listed for the first host (where it's state is "shut off"), but not for the second one:
import libvirt import sys
class kvmhost: def __init__(self, host, keyfile): self.conn = self.connect_kvm(host, keyfile) self.doms = sorted(self.get_doms()) def connect_kvm(self, host, keyfile): try: conn = libvirt.openReadOnly('qemu+ssh://root@' + host + '/system?keyfile=' + keyfile) except libvirt.libvirtError as lve: print('Error: ' + str(lve)) sys.exit(1) return conn def get_doms(self): try: alldoms = self.conn.listDefinedDomains() except libvirt.libvirtError as lve: print('Error: ' + str(lve)) self.conn.close() sys.exit(1) return alldoms
host1 = kvmhost('host1', '/path/to/ssh_keyfile') host2 = kvmhost('host2', '/path/to/ssh_keyfile')
print(host1.doms) print(host2.doms)
What am I doing wrong here or: is there a missbehavior in libvirt or the python module? This is expected behaviour of the listDefinedDomains() API call - though admittedly somewhat stupid behaviour.
Originally libvirt has a listDomainsIDs API call that only listed guests that were running.
We then added listDefinedDomains() call that only listed guests that were *not* running.
So to get a complete list of guests on the host you had to use *both* listDomainsIDs and listDefinedDomains().
This had a built-in race condition if a guest started or stopped in betweeen the 2 API calls. So we introduced 'listAllDomains' as a better API that can give you a list of *all* domains whether running or stopped.
Great, thanks for explaining this to me! Then listAllDomains seems like the way to go for me; but even the workaround of combining listDomainsIDs and listDefinedDomains() seems OK, if I cannot resolve the unknown procedure issue.
Using listAllDomains instead of listDefinedDomains gives:
libvirt: Remote Driver error : unknown procedure: 273 I'm really surprised to see that error - this API call has existed since libvirt 0.9.13 and you say you have 1.3.1 which is more than new enough
I'm very sorry, my bad: I've queried the wrong server from out of python. You are right: The Host which has this issue is of libvirt version 0.9.2. Testing the call against more recent libvirt works. Thank you for helping me identifying this fail.
What is the difference between listAllDomains and listDefinedDomains at all? Essentially listAllDomains() is what any app using modern libvirt should be using. We recommend ignoring listDefinedDomains & listDomainIDs unless you need to work with older (ancient) libvirt
Regards, Daniel
Best regars, Marc --- Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft. https://www.avast.com/antivirus
participants (3)
-
Daniel P. Berrange
-
Marc Richter
-
Pavel Hrdina