[augeas-devel] Migrating config file formats

Raphaël Pinson raphink at gmail.com
Wed Aug 1 14:03:59 UTC 2012


Hi Doug,


Sorry for this very long silence.

I just went on and reviewed your lens. It looks really nice. The idea of
storing the type of quote in a node is interesting, but I think it would be
really great if we could do without.

Could you add some inline doc (see keepalived.aug for example) to it please?


Raphaël



On Mon, May 14, 2012 at 10:08 PM, Doug Warner <doug at warner.fm> wrote:

> Here's my current lens for managing the /etc/conf.d/net file for gentoo; it
> uses the @syntax to map between baselayout 1 and 2.
>
> The big thing is the difference in handling quoting; the old lens would
> allow
> you to switch between quoting styles within a single variable (since it
> was a
> real array) but now it's forced to one quoting style per-array.  I can
> think
> of situations where this might bite you (including literal $'s) but I can't
> think of a good way to handle it.
>
> -Doug
>
>
> On 04/25/2012 06:09 PM, Raphaël Pinson wrote:
> > On Wed, Apr 25, 2012 at 10:09 PM, Doug Warner <doug at warner.fm> wrote:
> >> Sorry for the long delay here; starting to come back around to this
> problem :)
> >>
> >> I really like your idea for supporting multiple syntaxes here and
> marking them
> >> with this type of "version" string (you could label each syntax for each
> >> matching version to make it easier to understand what is going on).
> >
> >
> > You need to leave one syntax without a "@syntax" node (probably the
> > most recent syntax). The reason for this is that otherwise, this
> > parameter would become necessary for the tree to be valid, and users
> > would have to specify which syntax they want to use. It's much easier
> > if users don't care about it and just get the newest syntax by
> > default, without having to even know that "@syntax" nodes exist.
> >
> >
> >> So, related to this; would it be possible to include an external lens to
> >> handle the parsing for the "old version" and write the new version
> inside the
> >> current file?  I was thinking of just continuing to use the ShellVars
> lens to
> >> parse the line for the "old version" and tag it the appropriate syntax
> version
> >> and then write the new one as the default.
> >
> >
> > Sure, that's possible, but there are conditions. The example I gave
> > was quite simple (even simplistic). You have to avoid ambiguity in the
> > Augeas bidirectional transformations. That means:
> >
> > * No ambiguity on keys (same key mapping different syntaxes with
> > different lenses);
> > * No ambiguity on syntax (overlapping regexes for several syntaxes).
> >
> >
> > In the example I gave, I handled these two cases by:
> >
> > * Using a single label (in that case "key") declaration to avoid the
> > ambiguity on the keys, and handling the syntax cases inside this
> > single lens (declaring 3 lenses and using a union of them wouldn't
> > work, it would raise an ambiguity since the 3 keys would match the
> > same regex);
> > * Making sure syntaxes are non-overlapping (in this case, using
> > colons, commas or equal sign as separators ensure they cannot be
> > overlapping).
> >
> > The lens declaration could very well use more complex lenses, and even
> > lenses from other modules (such as Shellvars.lns), so long as it
> > follows these two rules.
> >
> > If you have a specific case, that could be interesting.
> >
> > Raphaël
> >
> >
> >
> >> On 02/11/2012 05:07 PM, Raphaël Pinson wrote:
> >>> After thinking about it some more, I think it could be useful to get
> >>> to a standard using subnodes.
> >>>
> >>> Here is an example, unrelated to the suggested problem:
> >>>
> >>>
> >>> module Migration =
> >>>
> >>> (* There are 3 possible syntaxes for a line
> >>>    The last one doesn't have a "@syntax" subnode, it's the default -
> >>> newest - syntax *)
> >>> let line = [ key Rx.word .
> >>>              ( (Sep.colon . store Rx.word . [ label "@syntax" . value
> "1" ])
> >>>              | (Sep.space . store Rx.word . [ label "@syntax" . value
> "2" ])
> >>>              | (Sep.equal . store Rx.word) )
> >>>              . Util.eol ]
> >>>
> >>> let lns = line*
> >>>
> >>> (* Now for some tests *)
> >>> let full = "foo:bar\nfoo=baz\nfoo baa\n"
> >>>
> >>> (* Get all kind of syntaxes *)
> >>> test lns get full =
> >>>   { "foo" = "bar"
> >>>     { "@syntax" = "1" }
> >>>   }
> >>>   { "foo" = "baz" }
> >>>   { "foo" = "baa"
> >>>     { "@syntax" = "2" }
> >>>   }
> >>>
> >>> (* Migrate all to new syntax *)
> >>> test lns put full after
> >>>    rm "//@syntax" =
> >>>    "foo=bar\nfoo=baz\nfoo=baa\n"
> >>>
> >>> (* Force syntax 1 for last entry *)
> >>> test lns put full after
> >>>    set "/foo[3]/@syntax" "1" =
> >>>    "foo:bar\nfoo=baz\nfoo:baa\n"
> >>>
> >>>
> >>>
> >>> Could that be an interesting approach in general?
> >>>
> >>> Raphaël
> >>>
> >>>
> >>>
> >>> 2012/1/26 Raphaël Pinson <raphink at gmail.com>:
> >>>> Hi Doug,
> >>>>
> >>>> On Thu, Jan 26, 2012 at 4:07 PM, Doug Warner <doug at warner.fm> wrote:
> >>>>> I'm working on a lens to work with Gentoo's new /etc/conf.d/net
> format and I
> >>>>> realized I need to convert their old format to the new format.
> >>>>>
> >>>>> What's the best way to migrate from one format to another?  I have
> my lens
> >>>>> mostly working for the new format now, but I realized I might need
> to parse
> >>>>> both versions; but then I thought that it might not update when
> augeas
> >>>>> reads/writes the config file.
> >>>>>
> >>>>> I am using puppet to manage these files; so the values are typically
> set each
> >>>>> run; I'm hoping that would cause augeas to write down the new format
> rather
> >>>>> than leave it the old version.
> >>>>>
> >>>>> I guess the last option is to wipe out the old file when I upgrade
> and let
> >>>>> puppet/augeas write down the new file, but that seems painful as
> well.
> >>>>>
> >>>>> Any recommendations on what to do here?
> >>>>>
> >>>>
> >>>>
> >>>> That's a very interesting question. I see two ways of doing this:
> >>>> * write a single lens which will map both syntaxes to different nodes
> >>>> in the tree, and use the "move" command to migrate;
> >>>> * or write two lenses bound to two different files (file.old and
> >>>> file.new or something similar) and use the "move" command to migrate.
> >>>>
> >>>>
> >>>> Here is a (minimalistic) proof of concept using the first option:
> >>>>
> >>>> $ cat myconfig.aug
> >>>> module MyConfig =
> >>>>
> >>>> autoload xfm
> >>>>
> >>>> let old_record =
> >>>>   let entry = [ Util.del_str "\""
> >>>>               . label "entry"
> >>>>               . store /[0-9.\/]+/
> >>>>               . Util.del_str "\"" ]
> >>>>   in [ label "old_record" . store Rx.word
> >>>>        . Util.del_str "=("
> >>>>        . Build.opt_list entry Sep.space
> >>>>        . Util.del_str ")" . Util.eol ]
> >>>>
> >>>> let new_record =
> >>>>   let entry = [ label "entry"
> >>>>               . store /[0-9.\/]+/ ]
> >>>>   in [ label "new_record" . store Rx.word
> >>>>        . Util.del_str "=\""
> >>>>        . Build.opt_list entry Util.eol
> >>>>        . Util.del_str "\"" . Util.eol ]
> >>>>
> >>>>
> >>>> let lns = old_record | new_record
> >>>>
> >>>> let filter = incl "/file"
> >>>>
> >>>> let xfm = transform lns filter
> >>>>
> >>>> $ cat fakeroot/file
> >>>> config_eth0=("192.168.0.1/24" "192.168.0.2/24")
> >>>>
> >>>> $ augtool -I . -r fakeroot
> >>>> /files
> >>>> /files/file
> >>>> /files/file/old_record = "config_eth0"
> >>>> /files/file/old_record/entry[1] = "192.168.0.1/24"
> >>>> /files/file/old_record/entry[2] = "192.168.0.2/24"
> >>>> rpinson at rpinson:~/bas/augeas_migration$ augtool -I . -r fakeroot/
> >>>> augtool> print /files/
> >>>> /files
> >>>> /files/file
> >>>> /files/file/old_record = "config_eth0"
> >>>> /files/file/old_record/entry[1] = "192.168.0.1/24"
> >>>> /files/file/old_record/entry[2] = "192.168.0.2/24"
> >>>> augtool> mv /files/file/old_record /files/file/new_record
> >>>> augtool> print /files/
> >>>> /files
> >>>> /files/file
> >>>> /files/file/new_record = "config_eth0"
> >>>> /files/file/new_record/entry[1] = "192.168.0.1/24"
> >>>> /files/file/new_record/entry[2] = "192.168.0.2/24"
> >>>> augtool> save
> >>>> Saved 1 file(s)
> >>>>
> >>>> $ cat fakeroot/file
> >>>> config_eth0="192.168.0.1/24
> >>>> 192.168.0.2/24"
> >>>>
> >>>>
> >>>> Note that you can combine this with the -b flag to keep the old
> version at hand.
> >>>>
> >>>>
> >>>> Raphaël
> >>
> >>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20120801/cc5f3827/attachment.htm>


More information about the augeas-devel mailing list