dhiltgen / docker-machine-kvm

KVM driver for docker-machine
Apache License 2.0
376 stars 117 forks source link

Use the libvirt API to obtain DHCP leases. #21

Closed cmars closed 6 years ago

cmars commented 7 years ago

Requires libvirt >= 1.2.6 and recent version of libvirt-go. The tag libvirt.1.2.14 is required by libvirt-go to enable its use, since a wider range of libvirt versions are supported there.

Why use the libvirt API? Well, besides a simpler implementation, and less dependent on libvirtd's files, etc... I'm interested in it primarily because I'd like to run this plugin in an apparmor-restricted environment that only allows access to the libvirtd socket. Pretty harsh, but that's what I've got to work with.

So I wasn't sure of the minimum version of libvirt you want to support with this plugin. If you want the other IP lookup methods back, I'm happy to add them back in as fallbacks, or used when the libvirt.1.2.14 build tag isn't set. However, I thought I'd be a little bold and see if you really needed them. Anyway, let me know!

dhiltgen commented 7 years ago

Hmm... this implies Ubuntu 14.04, and other older LTS distro's will no longer work without jumping through hoops.

I do like that there's a better API to gather this now. Thanks for trying to clean this up!

In order to keep this working with older distro's lets add them back as fallbacks, then at some point in the future we can drop them once those older distro's aren't as heavily used.

cmars commented 7 years ago

I've done just this, but I'm now worried it's not enough for supporting older distros, because the resulting binary is going to be dynamically-linked to libvirt.

I think to really do this right, I need to move getIPByMACFromAPI to two separate source files, one with // +build libvirt.1.2.14 and one with // +build !libvirt.1.2.14. The latter implementation could be a stub that just returns fmt.Errorf("not supported on this host").

Then I'd just need to update the Makefile to set the tags accordingly, and we can build for newer and older libvirts. For my use case, the API method works well, because I'm running in a chroot that has access to the libvirt socket but not /var/lib/... in general.

mikefaille commented 7 years ago

You can possibly detect libvirtd version by interrogating it and keeping theses 2 implementations at same time.

dhiltgen commented 7 years ago

Adding additional smarts to the makefile to detect libvirt version and build accordingly sounds like a reasonable compromise to allow this to move forward.