[augeas-devel] [Interfaces] Draft lense

Free Ekanayaka free at 64studio.com
Wed Aug 20 18:58:55 UTC 2008


Hi Raphaël,

|--==> Raphaël Pinson writes:

  >>it would generate a tree like:
  >>
  >>{ "auto"
  >>{ "1" = "lo" }
  >>{ "2" = "eth0" } }
  >>{ "auto"
  >>{ "1" = "eth1" } }
  >>
  >>which is closer to the actual configuration file, but probably less
  >>parsable than:
  >>
  >>{ "auto" = "lo" }
  >>{ "auto" = "eth0" }
  >>{ "auto" = "eth1" }
  >>

  RP> If I'm not wrong, this tree would pose a problem on put, because it's not
  RP> reversible. From looking at the tree, you can't tell how to represent it
  RP> back in the file, so there will be a conflict imo.

Yes, I guessed something like that, but I also though that the engine
could remember the original string. Not a big deal though. I've now
implemented the auto stanza as seq, pretty like sshd.aug.

  RP> This is a problem with put. When augeas meets a "comment" node, it doesn't
  RP> know if it's an option named "comment" or a comment, hence the conflict. To
  RP> fix this and make it clearer, we began to rename the comment nodes into
  RP> "#comment" some time ago. My local repository is like this, but it's not
  RP> committed into the main repository yet so I forgot to tell you about it. You
  RP> can change 'label "comment"' in your util.aug and it should fix the issue.

Thanks a lot, that fixed the problem indeed. Any chance to get it
committed in the official repo?

Below you find the latest version of the interface lens, which is
starting to shape good.

The main pending issue now are comments at the end of line, like:

auto lo eth0 # Take me to the net

I've tried to replace eol with (eol|comment):

let auto    = [ array /(allow-)?auto/ "auto" . eol . (comment|empty)* ]

with

let auto    = [ array /(allow-)?auto/ "auto" . (eol|comment). . (comment|empty)* ]

But I get this error:
  
lenses/interfaces.aug:26.3-.83:Failed to compile auto
lenses/interfaces.aug:26.19-.62:exception: ambiguous concatenation
      'auto\\\nA#A\n' can be split into
      'auto\\\nA|=|#A\n'

     and
      'auto\\\nA#A|=|\n'

Thanks again for you help!

Ciao,

Free

============ interfaces.aug ===============

(* Intefraces module for Augeas               *)
(* Author: Free Ekanayaka <free at 64studio.com> *)

module Interfaces =
   autoload xfm

   (* Define useful primitives *)
   let eol          = Util.eol
   let value_to_eol = store /([^\\ \t\n].*[^\\ \t\n]|[^\\ \t\n])/
   let value_to_spc = store /[^\\ \t\n]+/
   let spc = del /([ \t]+|[ \t]*\\\\\n[ \t]*)/ " "

   (* Define comment *)
   let comment = Util.comment
   let empty   = Util.empty

   (* Define a generic entry *)
   let entry (l:string) = [ spc . label l . value_to_spc ]

   (* Define stanzas *)
   let array (r:regexp) (t:string) = del r t . label t . counter t . [ spc . seq t . value_to_spc ]+
   let type (t:string) = del t t . label t . spc . value_to_spc

   let words  = /(iface|auto|allow-[a-z-]+|mapping)/
   let option = [  del /[ \t]*/ "   " . key  ( /[a-z-]+/ - words ) . spc . value_to_eol . eol ]

   let auto    = [ array /(allow-)?auto/ "auto" . eol . (comment|empty)* ]
   let iface   = [ type "iface" . entry "family" . entry "method" . eol . (option | comment | empty)* ]
   let mapping = [ type "mapping" . eol . (option|comment|empty)* ]
   let hotplug = [ type "allow-hotplug" . eol . (comment|empty)* ]

   (* Define stanza *)
   let stanza = (iface | auto | mapping | hotplug)

   (* Define lens *)
   let lns = ( comment | empty )* . stanza*

   let filter = incl "/etc/network/interfaces"
              . Util.stdexcl

   let xfm = transform lns filter

============ test_interfaces.aug ===============

module Test_interfaces = 

    let conf ="# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface

auto lo eth0
allow-hotplug eth1

iface lo inet \
 loopback

mapping eth0
	script /usr/local/sbin/map-scheme
map HOME eth0-home
     map \
 WORK eth0-work

iface eth0-home inet static
address 192.168.1.1
     netmask 255.255.255.0
#        up flush-mail

iface eth0-work inet dhcp

allow-auto eth1
iface eth1 inet dhcp
"

    test Interfaces.lns get conf =
        { "#comment" = "This file describes the network interfaces available on your system"}
        { "#comment" = "and how to activate them. For more information, see interfaces(5)." }
        { "#comment" = "The loopback network interface" }
        {}
        { "auto"
            { "1" = "lo" }
            { "2" = "eth0" } }
        { "allow-hotplug" = "eth1" 
            {} }
        { "iface" = "lo"
            { "family" = "inet"}
            { "method" = "loopback"} {} }
        { "mapping" = "eth0"
            { "script" = "/usr/local/sbin/map-scheme"}
            { "map" = "HOME eth0-home"}
            { "map" = "WORK eth0-work"} 
            {} }
        { "iface" = "eth0-home"
            { "family" = "inet"}
            { "method" = "static"}
            { "netmask" = "255.255.255.0" }
            { "#comment" = "up flush-mail" }
            { "up" = "flush-mail" }
            {} }
        { "iface" = "eth0-work"
            { "family" = "inet"}
            { "method" = "dhcp"}
            {} }
        { "auto"
            { "1" = "eth1" } }
        { "iface" = "eth1"
            { "family" = "inet"}
            { "method" = "dhcp"} }





More information about the augeas-devel mailing list