
On Mon, Feb 15, 2016 at 05:38:37PM +0100, Michal Privoznik wrote:
Are you tired of remembering IP addresses for your domains? Do you have enough of configuring static IPs so that you can add them to your hosts file? Then libvirt NSS module is exactly what you need!
NSS does a lot in a Linux host. These patches aim at translating domain names into IP addresses. All you need to do, is install libnss_libvirt.so.2 (e.g. via 'make install' ran from source dir), enable the module in nsswitch.conf:
$ grep libvirt /etc/nsswitch.conf hosts: files dns libvirt
and you're all set. Now you can just:
$ ping $mydomain $ ssh user@$mydomain
or anything you'd like. The only limitation is that it has to be libvirt who has assigned the domain IP address. The limitation comes from implementation in which '/var/lib/libvirt/dnsmasq/*.status' files are parsed when looking up a hostname.
What's beautiful on this feature is that it helps any users regardless of their systemd attitude. On systemd hosts there already exists a similar module 'mymachines' which takes its data from machined. And libvirt does communicate with machined when creating a domain. But unfortunately at that time we know nothing about guest's IPs and therefore do not tell them to machined, which in turn can't tell anything to mymachines module. To make things worse, machined seems to be lacking an API to tell it the addresses later on when libvirt finds out. Therefore even systemd distros will benefit from this feature.
Nice. For a similar purpose I hacked up simplec a while ago: https://github.com/agx/simplec it works by fetching domain IPs using our APIs and stores them in a file for a dnsmasq instance to read. This allows to even collect IPs from remote URIs. Cheers, -- Guido