[libvirt] [PATCH 0/6] NSS module for libvirt

Michal Privoznik mprivozn at redhat.com
Mon Feb 15 16:38:37 UTC 2016


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.

If the feature makes its way in, I'll describe all the steps in a
wiki (hence, no documentation in this patch set - although, if
you have a bright idea where should I put it, I'm all ears).


Enjoy!

Michal Privoznik (6):
  Export virLease* functions for leases file handling
  virjson: Resolve const correctness
  Initial support for NSS plugin skeleton
  nss: Implement _nss_libvirt_gethostbyname3_r
  Implement _nss_libvirt_gethostbyname4_r
  nss: Introduce a test

 cfg.mk                      |   2 +-
 configure.ac                |   2 +
 m4/virt-nss.m4              |  51 ++++++
 po/POTFILES.in              |   1 +
 src/Makefile.am             |   1 +
 src/libvirt_private.syms    |   6 +
 src/network/leaseshelper.c  | 271 +--------------------------
 src/util/virjson.c          |  58 +++---
 src/util/virjson.h          |  54 +++---
 src/util/virlease.c         | 304 ++++++++++++++++++++++++++++++
 src/util/virlease.h         |  44 +++++
 tests/Makefile.am           |  18 ++
 tests/nssdata/virbr0.status |  14 ++
 tests/nssmock.c             | 140 ++++++++++++++
 tests/nsstest.c             | 184 +++++++++++++++++++
 tools/Makefile.am           |  45 +++++
 tools/nss/libvirt_nss.c     | 436 ++++++++++++++++++++++++++++++++++++++++++++
 tools/nss/libvirt_nss.h     |  52 ++++++
 tools/nss/libvirt_nss.syms  |  12 ++
 19 files changed, 1368 insertions(+), 327 deletions(-)
 create mode 100644 m4/virt-nss.m4
 create mode 100644 src/util/virlease.c
 create mode 100644 src/util/virlease.h
 create mode 100644 tests/nssdata/virbr0.status
 create mode 100644 tests/nssmock.c
 create mode 100644 tests/nsstest.c
 create mode 100644 tools/nss/libvirt_nss.c
 create mode 100644 tools/nss/libvirt_nss.h
 create mode 100644 tools/nss/libvirt_nss.syms

-- 
2.4.10




More information about the libvir-list mailing list