[augeas-devel] Re: using defnode to add new nodes
Kjetil Torgrim Homme
kjetilho at linpro.no
Thu Jun 18 15:32:37 UTC 2009
David Lutterkort <lutter at redhat.com> writes:
> On Wed, 2009-06-17 at 11:54 +0200, Kjetil Torgrim Homme wrote:
>> right. I'm not suggesting that the variable defined by defnode is
>> changed *after* defnode returns. I'm just suggesting that the node
>> defnode creates is included in the node list returned.
>
> Aaah .. all kinds of lights are going off .. you are saying that
> after doing a 'set' inside defnode, just stick the new node into the
> variable ? Yeah, I like that .. happen to have a patch ? ;)
oh, that's great! unfortunately, I haven't quite understood the code
well enough yet. I might have another go later.
>> I'm sure it's possible to come up with problematic examples, and I
>> encourage you to do so, so that we can discuss how Augeas is to be
>> *used*. a little (but not much) more tricky example: defnode
>> doesn't work with the hosts lens, since it creates hosts/N/ rather
>> than hosts[N].
>
> Just as an aside: the reason the hosts lens creates a
> /files/etc/hosts/N node rather than something like
> /files/etc/hosts/entry[N] (i.e. uses the 'seq' lens) has to do how
> spacing is preserved. Basically, with the current scheme, Augeas can
> detect that an entry has been deleted, and make sure comments
> etc. stay in the right place. With the alternate scheme, deleting a
> host entry in the middle would cause all lines after the deleted
> line to shift up one line, past comments.
that doesn't seem to happen to me, but it looks like whitespace is
reset to lens defaults when I remove a node in the middle of, e.g.,
services. here's an excerpt from the diff produced when I removed the
junk entry I had added manually.
@@ -26,59 +26,58 @@
echo 7/tcp
echo 7/udp
# comment in front of junk
-junk 8/udp
# comment after junk
-discard 9/tcp sink null
+discard 9/tcp sink null
discard 9/udp sink null
systat 11/tcp users
systat 11/udp users
daytime 13/tcp
daytime 13/udp
-qotd 17/tcp quote
+qotd 17/tcp quote
qotd 17/udp quote
-msp 18/tcp # message send protocol
+msp 18/tcp# message send protocol
msp 18/udp # message send protocol
-chargen 19/tcp ttytst source
+chargen 19/tcp ttytst source
[...]
isn't it strange that lines with udp and tcp behave differently? this
is 0.5.1, btw.
>> augtool> defnode host '/files/etc/hosts/*/*[../ipaddr = "127.0.0.1"]'
>> Failed
>>
>> first of all, such inconsistencies across lenses should be fixed.
>> secondly, I think it's quite reasonable that in the non-matching case,
>> defnode would create a new object at the level of the first wildcard.
>> in either case I would like to be able to say
>>
>> set $host/ipaddr 127.0.0.1
>> set $host/canonical localhost
>> set $host/alias[1] localhost.localdomain
>
> The problem is that at the point where the node is created, I have
> no idea what an appropriate name for the new node would be (since I
> only have the wildcard, I don't even know what regexp the label is
> supposed to match)
well... "001"? :-) no, I see it's hard to do without possibly dubious
heuristics.
--
Kjetil T. Homme
Redpill Linpro AS - Changing the game
More information about the augeas-devel
mailing list