digitalocean / go-libvirt

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

Support for modular libvirt daemons #171

Open folliehiyuki opened 2 years ago

folliehiyuki commented 2 years ago

Currently the socket is defined as a variable here https://github.com/digitalocean/go-libvirt/blob/15feff002086ca5276717d866e19ebf9e082f343/socket/dialers/local.go#L10

so it only works with Monolithic daemon mode (libvirtd) and not the Modular daemons mode (virtqemud, virtstoraged,...).

Ref: https://libvirt.org/daemons.html

connorkuehl commented 2 years ago

Are you able to connect to the modular sockets with the dialers package? Something like this:

dialer := dialers.NewLocal(dialers.WithSocket("/var/run/libvirt/virtqemud"))
lv := libvirt.NewWithDialer(dialer)
err := lv.Connect()
defer lv.Disconnect()
folliehiyuki commented 2 years ago

Sorry that I'm not familiar with Go. I modified the snippet above a little:

package main

import (
    "github.com/digitalocean/go-libvirt"
    "github.com/digitalocean/go-libvirt/socket/dialers"
    "github.com/sirupsen/logrus"
)

func main() {
    dialer := dialers.NewLocal(dialers.WithSocket("/var/run/libvirt/virtqemud-sock"))
    lv := libvirt.NewWithDialer(dialer)
    if err := lv.Connect(); err != nil {
        logrus.Fatal(err)
    }
    defer lv.Disconnect()
}

Running it with go run main.go doesn't return any errors (and it returns 0) so I guess it connects successfully.

folliehiyuki commented 2 years ago

What I want to ask here is to support dynamic socket. So instead of relying on 1 defined socket, we can detect which modular socket we need to connect to based on the API call.

On a normal system, 1 modular daemon alone is kind of useless, but also people might not want to enable libvirtd as they don't use all libvirt features.

connorkuehl commented 2 years ago

Ah, I see. That makes sense. I can't promise this will get done in the near future, but if someone else beats one of us and submits patches, I'm happy to review them.

Thanks for filing this feature request :slightly_smiling_face: