[augeas-devel] Default label for a node in a path expression
Raphaël Pinson
raphael.pinson at camptocamp.com
Fri Dec 20 22:24:00 UTC 2013
Hello,
There's regularly people asking how to write idempotent set expressions.
With labeled nodes, we have the usual trick:
set foo[.='bar'] 'bar'
which creates the 'foo' node with the 'bar' value if it doesn't exist.
However, it's kind of a trick and it doesn't work with seq nodes, which
always require some kind of additional logic, such as onlyif in Puppet, or
a match('foo[.="bar"]').empty? kind of test.
It would be very useful to be able to set the default label for a node when
using set. I've thought of several ways, such as adding a new command, or
adding to the XPath language.
The first thing I've thought would be to add a new API call:
aug_set_default(path, default, value)
When path matches no nodes, default is used as the label to create a node.
That's not very practical though, and it doesn't work on several levels.
So I've thought maybe we could add to the XPath language:
set /path/to/*[default() = "foo"][. = "bar"] "bar"
If no node matching /path/to/* is found, then a new node would be created
using label "foo". This would allow for multiple level defaults, such as:
set /path/to/*[default() = "foo"][. = "bar"]/*[default = "foz"][. =
"baz"] "baz"
and defaults would be applied at each level. I don't know about the
feasability of this, but it would bring the most flexibility and it would
allow to easily write idempotent set commands for seq nodes, too:
set /path/to/*[default() = "01"][. = "bar"] "bar"
What are your thoughts on this?
Cheers,
--
Raphaël Pinson
Infrastructure Developer & Trainer
+33 479 26 57 93
+33 781 90 00 79
Camptocamp France
Savoie Technolac
BP 352
48, avenue du Lac du Bourget
73372 Le Bourget du Lac, Cedex
www.camptocamp.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20131220/4f3d1d86/attachment.htm>
More information about the augeas-devel
mailing list