[libvirt] Python listDefinedDomains broken?
Marc Richter
mr at in-telegence.net
Thu Jun 2 09:47:29 UTC 2016
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
More information about the libvir-list
mailing list