[augeas-devel] [PATCH] Interface lense
Free Ekanayaka
free at 64studio.com
Mon Aug 25 07:18:49 UTC 2008
# HG changeset patch
# User Free Ekanayaka <free at 64studio.com>
# Date 1219568237 -7200
# Node ID 85fecab260d15f7dd80a416380b8f32557f5545e
# Parent 4b9b71f3f91d5ab6e4c0ae3ffd68397c2ecdc5d4
Interface lense
diff -r 4b9b71f3f91d -r 85fecab260d1 lenses/interfaces.aug
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lenses/interfaces.aug Sun Aug 24 10:57:17 2008 +0200
@@ -0,0 +1,107 @@
+(* Intefraces module for Augeas
+ Author: Free Ekanayaka <free at 64studio.com>
+
+ Reference: man interfaces
+
+*)
+
+module Interfaces =
+ autoload xfm
+
+(************************************************************************
+ * USEFUL PRIMITIVES
+ *************************************************************************)
+
+let eol = Util.eol
+
+(* Define separators *)
+
+(* a line can be extended across multiple lines by making the last *)
+(* character a backslash, unless the line is a comment (see below) *)
+let sep_spc = del /([ \t]+|[ \t]*\\\\\n[ \t]*)/ " "
+
+(* Define fields *)
+let sto_to_eol = store /([^\\# \t\n].*[^\\ \t\n]|[^\\ \t\n])/
+let sto_to_spc = store /[^\\# \t\n]+/
+
+(* Define comments and empty lines *)
+
+(* note that the comment definition from Util does not support *)
+(* splitting lines with a backlash *)
+let comment = Util.comment
+
+let empty = Util.empty
+
+(* Define tree stanza_ids *)
+let stanza_id (t:string) = key t . sep_spc . sto_to_spc
+let stanza_param (l:string) = [ sep_spc . label l . sto_to_spc ]
+
+(* Define reseverved words *)
+let stanza_word = /(iface|auto|allow-[a-z-]+|mapping)/
+
+(* Define additional lines for mluti-line stanzas *)
+let stanza_option = [ del /[ \t]*/ " "
+ . key ( /[a-z-]+/ - stanza_word )
+ . sep_spc
+ . sto_to_eol
+ . eol ]
+
+(************************************************************************
+ * AUTO
+ *************************************************************************)
+
+let array (r:regexp) (t:string) = del r t . label t . counter t
+ . [ sep_spc . seq t . sto_to_spc ]+
+let auto = [ array /(allow-)?auto/ "auto" . (comment|eol) ]
+
+(************************************************************************
+ * HOTPLUG
+ *************************************************************************)
+
+let hotplug = [ stanza_id "allow-hotplug" . (comment|eol) ]
+
+(************************************************************************
+ * MAPPING
+ *************************************************************************)
+
+let mapping = [ stanza_id "mapping"
+ . ( eol | ((eol . empty*)? . comment+) )
+ . empty*
+ . stanza_option
+ . (stanza_option|comment|empty)* ]
+
+(************************************************************************
+ * IFACE
+ *************************************************************************)
+
+let iface = [ stanza_id "iface"
+ . stanza_param "family"
+ . stanza_param "method"
+ . ( eol | ((eol . empty*)? . comment+) )
+ . empty*
+ . ( stanza_option . (stanza_option|comment|empty)* )? ]
+
+(************************************************************************
+ * STANZAS
+ *************************************************************************)
+
+(* The auto and hotplug stanzas always consist of one line only, while
+ iface and mapping can spand along more lines. Comment nodes are
+ inserted in the tree as direct children of the root node only when they
+ come after an auto or hotplug stanza, otherwise they are considered part
+ of a iface or mapping block *)
+
+let stanza_single = (auto|hotplug) . (comment|empty)*
+let stanza_multi = iface|mapping
+
+(************************************************************************
+ * LENS & FILTER
+ *************************************************************************)
+
+ let lns = (comment|empty)* . (stanza_multi | stanza_single)*
+
+ let filter = incl "/etc/network/interfaces"
+ . Util.stdexcl
+
+ let xfm = transform lns filter
+
diff -r 4b9b71f3f91d -r 85fecab260d1 lenses/tests/test_interfaces.aug
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lenses/tests/test_interfaces.aug Sun Aug 24 10:57:17 2008 +0200
@@ -0,0 +1,80 @@
+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 # Take me to the net
+allow-hotplug eth1
+
+iface lo inet \
+ loopback
+
+mapping eth0 # Home sweet home
+ 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 # This is easy
+
+mapping eth1
+ # I like mapping ...
+ # ... and I like comments
+
+ script\
+ /usr/local/sbin/map-scheme
+"
+
+ 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" }
+ { "#comment" = "Take me to the net" } }
+ { "allow-hotplug" = "eth1" }
+ { "iface" = "lo"
+ { "family" = "inet"}
+ { "method" = "loopback"} {} }
+ { "mapping" = "eth0"
+ { "#comment" = "Home sweet home" }
+ { "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" }
+ { "#comment" = "up flush-mail" }
+ {} }
+ { "iface" = "eth0-work"
+ { "family" = "inet"}
+ { "method" = "dhcp"}
+ {} }
+ { "auto"
+ { "1" = "eth1" } }
+ { "iface" = "eth1"
+ { "family" = "inet"}
+ { "method" = "dhcp"}
+ { "#comment" = "This is easy" }
+ {} }
+ { "mapping" = "eth1"
+ { "#comment" = "I like mapping ..." }
+ { "#comment" = "... and I like comments" }
+ {}
+ { "script" = "/usr/local/sbin/map-scheme"} }
More information about the augeas-devel
mailing list