[augeas-devel] [Interfaces] Draft lense

Free Ekanayaka free at 64studio.com
Wed Aug 20 14:35:20 UTC 2008


Hi Raphaël,

below you find another version of the lens, which implements many of
the hints you gave me. I've removed the seq objects and now options of
iface and mapping stanzas are properly parsed even when they are not
prepended by spaces or tabs.

Pending issues now are:

1) The "auto" stanza does not support more than one interface, that
means if the parser meets:

auto lo eth0

it will not generate the tree

{ "auto" = "lo" }
{ "auto" = "eth0" } }

2) Comments inside a iface or mapping stanza break the parser. Ideally
something like:

# My outer comment
iface eth0 inet static
     address 192.168.1.1
#    up flush-mail
     netmask 255.255.255.0

should generate:

{ "comment" = "My outer comment"}
{ "iface" = "eth0"
    { "family" = "inet"}
    { "method" = "static"}
    { "address" = "192.168.1.1" }
    { "comment" = "    up flush-mail" } }
    { "netmask" = "255.255.255.0" }
  
but I don't know how to tell the parser that the second comment
belongs to the "iface" tree.

3) Lines splitted with the backslash character create problems, for
example:

iface lo inet \
  loopback

I've tried to replace:

let spc          = Util.del_ws_spc

with

let spc = del /([ \t]+|[ \t]*\\\n[ \t]*)/ " "

but I'm getting:

Test run encountered exception:
lenses/tests/test_interfaces.aug:29.9-.32:exception: Short iteration
    Error encountered here (205 characters into string)
    <auto lo\nallow-hotplug eth1\n\n|=|iface lo inet \\\n loopback\n\nm>

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 type (r:regexp) (t:string) = del r 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    = [ type /(allow-)?auto/ "auto" . eol ]
   let iface   = [ type /iface/ "iface" . entry "family" . entry "method" . eol . option* ]
   let mapping = [ type /mapping/ "mapping" . eol . option* ]
   let hotplug = [ type /allow-hotplug/ "allow-hotplug" . eol ]

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

   (* Define lens *)
   let lns = ( empty | comment | 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
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" = "lo" }
        { "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"}
            { "address" = "192.168.1.1" }
            { "netmask" = "255.255.255.0" }
            { "up" = "flush-mail" } }
        {}
        { "iface" = "eth0-work"
            { "family" = "inet"}
            { "method" = "dhcp"} }
        {}
        { "auto" = "eth1" }
        { "iface" = "eth1"
            { "family" = "inet"}
            { "method" = "dhcp"} }




More information about the augeas-devel mailing list