[augeas-devel] Re: using defnode to add new nodes
Kjetil Torgrim Homme
kjetilho at linpro.no
Tue Jun 16 09:08:40 UTC 2009
David Lutterkort <lutter at redhat.com> writes:
> On Mon, 2009-06-15 at 12:50 +0200, Kjetil Torgrim Homme wrote:
>> I was trying to use defnode as a simple way to declare state
>> idempotently, and defnode seems to be the ticket. let's say I wanted
>> to add a new entry in /etc/services
>>
>> defnode svc '/files/etc/services/service-name[. = "foo" and protocol = "tcp"]' foo
>> set $svc/port 4711
>> set $svc/protocol tcp
>>
>> this works fine for known services, but when adding a new entry, it
>> fails.
>
> The problem is that 'defnode var path value' is roughly equivalent to
>
> if !exists(path)
> set path value
> end
> defvar var path
>
> The path you use will only find the service-name node for 'foo' if it
> has a protocol child set to 'tcp' - but the set that defnode does, does
> not create a protocol child. With that, you wind up with a defvar with a
> path that matches no nodes, and var contains the empty node set.
exactly. the bug is that it doesn't add the new node to the node set.
after all, it's not a dynamic evaluation, so adding it statically
should work. I dare say it's expected and wanted behaviour. an
orphaned node is not very useful.
augtool> print /files/etc/services/*[last()]
/files/etc/services/service-name[10313] = "foo"
augtool> print $svc
augtool> set /files/etc/services/service-name[10313]/port 4711
augtool> set /files/etc/services/service-name[10313]/protocol tcp
augtool> print $svc
augtool>
> Short of support for a full-blown 'if' (and the ensuing need for
> boolean expressions), I don't see how this could be implemented in
> augtool.
I do! :) although I couldn't quite get my head around the C code at
first attempt...
> Of course, if you use Augeas from your favorite programming language,
> you can easily achieve what you want.
I do not want "if" statements, "if" statements are fragile and you can
easily get uncovered cases etc. I want a declarative language, and
defnode + XPath is *almost* there for many uses.
--
Kjetil T. Homme
Redpill Linpro AS - Changing the game
More information about the augeas-devel
mailing list