4 ms·
> However, no one forces you to use KVM directly. There is libvirt, a nice friendly wrapper for low-level virtualization techniques such as KVM or BHyve. No, t
by st_goliath 6y ago
> However, no one forces you to use KVM directly. There is libvirt, a nice friendly wrapper for low-level virtualization techniques such as KVM or BHyve.
No, that's not what libvirt does. libvirt abstracts handling of tools like Qemu, or LXC. No lowlevel stuff.
When people talk about libvirt, they usually mean the libvirt daemon that manages VMs or containers using other programs and accepts XML machine descriptions as input.
The actual "libvirt" library is simply a front end library for talking to the daemon and is used internally by tools like virsh (CLI) or virtman (GUI tool).
Some ~7 years ago I used the libvirt library for a small in-house tool. It has the possibly shittiest API ever designed. No abstraction whatsoever, just a couple C functions that accept XML strings as input and possibly return XML responses from the daemon.
- asguy 6y ago> It has the possibly shittiest API ever designed. This was my experience as well. The only time I get near libvirt anymore is to read source; because sometimes it's the best documentation for a qemu feature.
- rwmj 6y ago(Part time libvirt developer here ...) I argued early on for libvirt to model things properly through a C API. Obviously I didn't succeed. I eventually wrote a bunch of "interesting" C macros to make it easier to create and submit XML documents: https://github.com/libguestfs/libguestfs-common/blob/master/utils/libxml2-writer-macros.h https://github.com/libguestfs/libguestfs-common/blob/master/... Example usage: https://github.com/libguestfs/libguestfs/blob/b9065fa7adc93123c53f4827e11dad6b210b7d4b/lib/launch-libvirt.c#L1154 https://github.com/libguestfs/libguestfs/blob/b9065fa7adc931... However these days when just about everything is a service accessed by shuffling poorly documented and type-unsafe JSON documents over the network, maybe libvirt was just ahead of its time ... [Libvirt XML is incredibly well documented, probably in some ways over documented.]
- outworlder 6y ago> It has the possibly shittiest API ever designed. Used libvirt for LXC, before "Docker" was the new kid on the block. Once we got it working it was great... but libvirt itself, ugh. There were some rubygems that abstracted some of the pain, that helped. Still the ugliness would poke through.
- qhwudbebd 6y agoI think you underappreciate libvirt here. The qemu command line interface is really quite ugly and awkward to use. You might imagine that, in wrapping it, libvirt might fail to make it worse. But they actually succeeded! (To be fair, if you're stuck for ideas for making something nastier, wrapping it in XML isn't a crazy starting point.)
- asguy 6y agoqemu has its own (often unnoticed) config file format `-readconfig fname`. I use it instead of the command line when things are getting out of hand.
- rwmj 6y ago-readconfig is incomplete. You cannot express all features (and even several common features) through the config file. Also the config file field names are sometimes different from the corresponding command line names. It's considered an appendix by the upstream developers so don't be surprised if it disappears one day.
- asguy 6y agoWhat features have you had problems with?
- dyasny 6y agoNo matter how shitty it is, nothing beats the qemu cli syntax. What horror...