[augeas-devel] [PATCH] Dhclient lens

Free Ekanayaka free at 64studio.com
Wed Aug 27 20:22:19 UTC 2008


# HG changeset patch
# User Free Ekanayaka <free at 64studio.com>
# Date 1219868519 -7200
# Node ID 715e29b93bc86728fdb541a59cfa48d42fdd52d1
# Parent  cff4cb60ca2b80ae886db42376dd2fc9877b67b3
Dhclient lens

diff -r cff4cb60ca2b -r 715e29b93bc8 lenses/dhclient.aug
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lenses/dhclient.aug	Wed Aug 27 22:21:59 2008 +0200
@@ -0,0 +1,163 @@
+(* Intefraces module for Augeas
+   Author: Free Ekanayaka <free at 64studio.com>
+
+   Reference: man dhclient.conf
+   The only difference with the reference syntax is that this lens assumes
+   that statements end with a new line, while the reference syntax allows
+   new statements to be started right after the trailing ";" of the
+   previous statement. This should not be a problem in real-life
+   configuration files as statements get usually splitted across several
+   lines, rather than merged in a single one.
+
+   TODO: support the "default", "supersede", "append" and "prepend"
+   statements
+*)
+
+module Dhclient =
+
+   autoload xfm
+
+(************************************************************************
+ *                           USEFUL PRIMITIVES
+ *************************************************************************)
+
+let eol               = Util.eol
+let comment           = Util.comment
+let empty             = Util.empty
+
+(* Define separators *)
+let sep_spc           = del /[ \t\n]+/ " "
+let sep_scl           = del /[ \t]*;/ ";"
+let sep_obr           = del /[ \t\n]*\{\n]*/" \{\n"
+let sep_cbr           = del /[ \t\n]*\}/ " \}"
+let sep_com           = del /[ \t\n]*,[ \t\n]*/ ","
+let sep_slh           = del "\/" "/"
+let sep_col           = del ":" ":"
+
+(* Define basic types *)
+let word              = /[A-Za-z0-9_.-]+(\[[0-9]+\])?/
+
+(* Define fields *)
+
+(* TODO: there could be a " " in the middle of a value ... *)
+let sto_to_spc        = store /[^\\#,;\{\}" \t\n]+|"[^\\#"\n]+"/
+let sto_number        = store /[0-9][0-9]*/
+
+(************************************************************************
+ *                         SIMPLE STATEMENTS
+ *************************************************************************)
+
+let stmt_simple_re    = "timeout"
+                      | "retry"
+                      | "select-timeout"
+                      | "reboot"
+                      | "backoff-cutoff"
+                      | "initial-interval"
+                      | "do-forward-updates"
+                      | "reject"
+
+let stmt_simple       = [ key stmt_simple_re
+                        . sep_spc
+                        . sto_to_spc
+                        . sep_scl
+                        . (eol|comment) ]
+
+
+(************************************************************************
+ *                          ARRAY STATEMENTS
+ *************************************************************************)
+
+(* TODO: the array could also be empty, like in the request statement *)
+let stmt_array_re     = "media"
+                      | "request"
+                      | "require"
+
+let stmt_array        = [ key stmt_array_re
+                        . sep_spc
+                        . counter "stmt_array"
+                        . [ seq "stmt_array" . sto_to_spc ]
+                        . [ sep_com . seq "stmt_array" . sto_to_spc ]*
+                        . sep_scl . (eol|comment) ]
+
+(************************************************************************
+ *                          HASH STATEMENTS
+ *************************************************************************)
+
+let stmt_hash_re      = "send"
+                      | "option"
+
+let stmt_hash         = [ key stmt_hash_re
+                        . sep_spc
+                        . [ key word . sep_spc . sto_to_spc ]
+                        . sep_scl
+                        . (eol|comment) ]
+
+(************************************************************************
+ *                         BLOCK STATEMENTS
+ *************************************************************************)
+
+let stmt_block_re     = "interface"
+                      | "lease"
+                      | "alias"
+
+let stmt_block_opt_re = "interface"
+                      | "script"
+                      | "bootp"
+                      | "fixed-address"
+                      | "filename"
+                      | "server-name"
+                      | "medium"
+                      | "vendor option space"
+
+(* TODO: some options could take no argument like bootp *)
+let stmt_block_opt    = [ key stmt_block_opt_re
+                         . sep_spc
+                         . sto_to_spc
+                         . sep_scl
+                         . (eol|comment) ]
+
+let stmt_block_date_re
+                      = "renew"
+                      | "rebind"
+                      | "expire"
+
+let stmt_block_date   = [ key stmt_block_date_re
+                        . [ sep_spc . label "weekday" . sto_number ]
+                        . [ sep_spc . label "year"    . sto_number ]
+                        . [ sep_slh . label "month"   . sto_number ]
+                        . [ sep_slh . label "day"     . sto_number ]
+                        . [ sep_spc . label "hour"    . sto_number ]
+                        . [ sep_col . label "minute"  . sto_number ]
+                        . [ sep_col . label "second"  . sto_number ]
+                        . sep_scl
+                        . (eol|comment) ]
+
+let stmt_block_arg    = sep_spc . sto_to_spc
+
+let stmt_block_entry  = sep_spc 
+                      . ( stmt_array
+                        | stmt_hash
+                        | stmt_block_opt
+                        | stmt_block_date )
+
+let stmt_block        = [ key stmt_block_re
+                        . stmt_block_arg?
+                        . sep_obr
+                        . stmt_block_entry+
+                        . sep_cbr
+                        . (eol|comment) ]
+
+(************************************************************************
+ *                              LENS & FILTER
+ *************************************************************************)
+
+let statement = (stmt_simple|stmt_array|stmt_hash|stmt_block)
+
+let lns               = ( empty
+                        | comment
+                        | statement )*
+
+let filter            = incl "/etc/dhcp3/dhclient.conf"
+                      . Util.stdexcl
+
+let xfm                = transform lns filter
diff -r cff4cb60ca2b -r 715e29b93bc8 lenses/tests/test_dhclient.aug
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lenses/tests/test_dhclient.aug	Wed Aug 27 22:21:59 2008 +0200
@@ -0,0 +1,126 @@
+module Test_dhclient = 
+
+    let conf ="  # Sample dhclient.conf
+    # Protocol timing
+timeout 3; # Expect a fast server
+retry 
+      10;
+# Lease requirements and requests
+request
+	subnet-mask, 
+  broadcast-address,
+	ntp-servers;
+# Dynamic DNS
+send
+	fqdn.fqdn 
+	  \"grosse.fugue.com.\";
+
+interface ep0 {
+   script /sbin/dhclient-script;
+   send dhcp-client-identifier 1:0:a0:24:ab:fb:9c;
+   send dhcp-lease-time 3600;
+   request subnet-mask, broadcast-address, time-offset, routers,
+          domain-name, domain-name-servers, host-name;
+   media media10baseT/UTP, \"media10base2/BNC\";
+}
+
+alias {
+  interface \"ep0\";
+  fixed-address 192.5.5.213;
+  option subnet-mask 255.255.255.255;
+}
+
+lease {
+  interface \"eth0\";
+  fixed-address 192.33.137.200;
+  medium \"link0 link1\";
+  vendor option space \"name\";
+  option host-name \"andare.swiftmedia.com\";
+  option subnet-mask 255.255.255.0;
+  option broadcast-address 192.33.137.255;
+  option routers 192.33.137.250;
+  option domain-name-servers 127.0.0.1;
+  renew 2 2000/1/12 00:00:01;
+  rebind 2 2000/1/12 00:00:01;
+  expire 2 2000/1/12 00:00:01;
+}
+"
+
+    test Dhclient.lns get conf =
+        { "#comment" = "Sample dhclient.conf" }
+        { "#comment" = "Protocol timing" }
+        { "timeout" = "3"
+           { "#comment" = "Expect a fast server" } }
+        { "retry" = "10" }
+        { "#comment" = "Lease requirements and requests" }
+        { "request" 
+           { "1" = "subnet-mask" }
+           { "2" = "broadcast-address" }
+           { "3" = "ntp-servers" } }
+        { "#comment" = "Dynamic DNS" }
+        { "send" 
+           { "fqdn.fqdn" = "\"grosse.fugue.com.\"" } }
+        {}
+        { "interface" = "ep0"
+           { "script" = "/sbin/dhclient-script" }
+           { "send" 
+               { "dhcp-client-identifier" = "1:0:a0:24:ab:fb:9c" } } 
+           { "send" 
+               { "dhcp-lease-time" = "3600" } } 
+           { "request" 
+               { "1" = "subnet-mask" }
+               { "2" = "broadcast-address" }
+               { "3" = "time-offset" }
+               { "4" = "routers" }
+               { "5" = "domain-name" }
+               { "6" = "domain-name-servers" }
+               { "7" = "host-name" } }
+           { "media" 
+               { "1" = "media10baseT/UTP" }
+               { "2" = "\"media10base2/BNC\"" } } }
+        {}
+        { "alias"
+           { "interface" = "\"ep0\"" }
+           { "fixed-address" = "192.5.5.213" }
+           { "option"
+               { "subnet-mask" = "255.255.255.255" } } }
+        {}
+        { "lease"
+           { "interface" = "\"eth0\"" }
+           { "fixed-address" = "192.33.137.200" }
+           { "medium" = "\"link0 link1\"" }
+           { "vendor option space" = "\"name\"" }
+           { "option"
+               { "host-name" = "\"andare.swiftmedia.com\"" } }
+           { "option"
+               { "subnet-mask" = "255.255.255.0" } }
+           { "option"
+               { "broadcast-address" = "192.33.137.255" } }
+           { "option"
+               { "routers" = "192.33.137.250" } }
+           { "option"
+               { "domain-name-servers" = "127.0.0.1" } }
+           { "renew"
+               { "weekday" = "2" }
+               { "year"    = "2000" }
+               { "month"   = "1" }
+               { "day"     = "12" }
+               { "hour"    = "00" }
+               { "minute"  = "00" }
+               { "second"  = "01" } }
+           { "rebind"
+               { "weekday" = "2" }
+               { "year"    = "2000" }
+               { "month"   = "1" }
+               { "day"     = "12" }
+               { "hour"    = "00" }
+               { "minute"  = "00" }
+               { "second"  = "01" } }
+           { "expire"
+               { "weekday" = "2" }
+               { "year"    = "2000" }
+               { "month"   = "1" }
+               { "day"     = "12" }
+               { "hour"    = "00" }
+               { "minute"  = "00" }
+               { "second"  = "01" } } }




More information about the augeas-devel mailing list