[augeas-devel] Parsing network-scripts/ifcfg-*
Alan Pevec
apevec at redhat.com
Mon Apr 21 22:45:03 UTC 2008
These are basically simple key = value lists, I cooked something from existing lentiles, feedback appreciated.
diff -r 73811a93b35f lenses/ifcfg.aug
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lenses/ifcfg.aug Tue Apr 22 00:40:45 2008 +0200
@@ -0,0 +1,24 @@
+(* Parsing network-scripts/ifcfg-* config files *)
+module Ifcfg =
+ autoload xfm
+
+ let eol = Util.del_str "\n"
+
+ let key_re = /([A-Z])+/
+ let eq = del /[ \t]*=[ \t]*/ "="
+ let value = /[^ \t][^\n]*(\n[ \t]+[^ \t\n]+)*/
+
+ let comment = [ del /(#.*)?[ \t]*\n/ "# \n" ]
+
+ let kv = [ key key_re . eq . store value . eol ]
+
+ let lns = (comment) * . (kv) *
+
+ let filter = (incl "/etc/sysconfig/network-scripts/ifcfg-*")
+ . Util.stdexcl
+
+ let xfm = transform lns filter
+
+(* Local Variables: *)
+(* mode: caml *)
+(* End: *)
diff -r 73811a93b35f lenses/tests/test_ifcfg.aug
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lenses/tests/test_ifcfg.aug Tue Apr 22 00:40:45 2008 +0200
@@ -0,0 +1,39 @@
+(* Test for Ifcfg module *)
+module Test_ifcfg =
+ let eth_static = "# Intel Corporation PRO/100 VE Network Connection
+DEVICE=eth0
+BOOTPROTO=static
+BROADCAST=172.31.0.255
+HWADDR=ab:cd:ef:12:34:56
+IPADDR=172.31.0.31
+NETMASK=255.255.255.0
+NETWORK=172.31.0.0
+ONBOOT=yes
+"
+ test Ifcfg.lns get eth_static =
+ { }
+ { "DEVICE" = "eth0" }
+ { "BOOTPROTO" = "static" }
+ { "BROADCAST" = "172.31.0.255" }
+ { "HWADDR" = "ab:cd:ef:12:34:56" }
+ { "IPADDR" = "172.31.0.31" }
+ { "NETMASK" = "255.255.255.0" }
+ { "NETWORK" = "172.31.0.0" }
+ { "ONBOOT" = "yes" }
+
+ test Ifcfg.lns put eth_static after
+ set "BOOTPROTO" "dhcp" ;
+ rm "IPADDR" ;
+ rm "BROADCAST" ;
+ rm "NETMASK" ;
+ rm "NETWORK"
+ = "# Intel Corporation PRO/100 VE Network Connection
+DEVICE=eth0
+BOOTPROTO=dhcp
+HWADDR=ab:cd:ef:12:34:56
+ONBOOT=yes
+"
+
+(* Local Variables: *)
+(* mode: caml *)
+(* End: *)
More information about the augeas-devel
mailing list