digitalocean / go-libvirt

Package libvirt provides a pure Go interface for interacting with Libvirt. Apache 2.0 Licensed.
Apache License 2.0
947 stars 131 forks source link

Inability to subscribe `metdata-change`, `device-added` and `device-removed` events #154

Closed oblazek closed 2 years ago

oblazek commented 2 years ago

I am trying to subscribe to these events (in the title) like following:

events, err := l.SubscribeEvents(ctx, libvirt.DomainEventIDDeviceAdded, []libvirt.Domain{})
if err != nil {
    log.Fatal(err)
}

and then reading from that channel, but there no event comes no matter what I do..

I can see all these in virsh event --all --loop:

event 'lifecycle' for domain instance-000005ad: Defined Added
event 'lifecycle' for domain instance-000005ad: Started Booted
event 'lifecycle' for domain instance-000005ad: Suspended Paused
event 'lifecycle' for domain instance-000005ad: Resumed Unpaused
event 'device-added' for domain instance-000005ad: net1
event 'metdata-change' for domain instance-000005ad: element http://openstack.org/xmlns/libvirt/nova/1.1

but only lifecycle events work fine and can be subscribe/read from:

events, err := l.SubscribeEvents(ctx, libvirt.DomainEventIDLifecycle, []libvirt.Domain{})
if err != nil {
    log.Fatal(err)
}

any chance I am just missing something? Btw trying to use this on a openstack host with libvirt 5:

# virsh version
Compiled against library: libvirt 5.0.0
Using library: libvirt 5.0.0
Using API: QEMU 5.0.0
Running hypervisor: QEMU 2.11.1
connorkuehl commented 2 years ago

Does it still behave this way if you populate the third argument slice with Domains to subscribe to?

events, err := l.SubscribeEvents(ctx, libvirt.DomainEventIDDeviceAdded, []libvirt.Domain{aDomain, anotherDomain})
if err != nil {
    log.Fatal(err)
}
oblazek commented 2 years ago

no, that doesn't help either :/ .. but I got a bit further when I used

events, err := p.libvirtClient.SubscribeQEMUEvents(ctx, d.Name)
if err != nil {
    log.Fatal(err)
}

but then I could only get DEVICE_DELETED but nothing like DEVICE_ADDED or METADATA_CHANGE

oblazek commented 2 years ago

fyi with a different library github.com/libvirt/libvirt-go-module it works just fine :/

with that I am subscribing to the events like this:

_, err := conn.DomainEventMetadataChangeRegister(nil, p.cbMetadadaChanged)
connorkuehl commented 2 years ago

Thanks, that's good information.

Would you be willing to share a stack trace of your reproducer program?

Just let it run, find its PID, and do a kill -s SIGABRT <PID> and paste it here or link to a pastebin somewhere?

oblazek commented 2 years ago

sounds good, will do that