[augeas-devel] How to get the content of /etc/hosts with the API ?

Dominique Dumont dominique.dumont at hp.com
Mon Jul 7 13:04:02 UTC 2008


Hello

I'm trying to integrate Augeas in Config::Model.

For this I need a way to get all the available values of some
configration files. Let's look at /etc/host for example.

First, I tried to use print(). The output of print can be used to get
all data from /etc/hosts, but since print() send its data to a file
descriptor, the data cannot be retrieved through the API. (Actually, I
could use IO::String in Perl, but that would drag a dependency outside
of core perl).

Then I've tried the match command that does not work as expected:

augtool> match /files/etc/hosts/*
/files/etc/hosts/1 = (none)
/files/etc/hosts/2 = (none)
[...]
augtool> match /files/etc/hosts/*/
/files/etc/hosts/1 = (none)
/files/etc/hosts/2 = (none)
[...]
augtool> match /files/etc/hosts/*/*
/files/etc/hosts/1/ipaddr = 127.0.0.1
/files/etc/hosts/1/canonical = localhost
/files/etc/hosts/2/ipaddr = ::1
/files/etc/hosts/2/canonical = ip6-localhost
/files/etc/hosts/2/alias = ip6-loopback
/files/etc/hosts/3/ipaddr = fe00::0
[...]

So the only way to get all the data from /etc/hosts is to use
"/files/etc/hosts/*/*" pattern. 

The only hitch is that I need to know the "depth" of the struture of
the configuration data to be able to get data. It works for /etc/hosts
with a depth of 2, but that's not a generic solution.

So could we have a "print" equivalent that would send the data back
through the API ?


All the best


-- 
Dominique Dumont 
"Delivering successful solutions requires giving people what they
need, not what they want." Kurt Bittner




More information about the augeas-devel mailing list