---
 lenses/resolv.aug            |  109
++++++++++++++++++++++++++++++++++++++++++
 lenses/tests/test_resolv.aug |   43 ++++++++++++++++
 2 files changed, 152 insertions(+), 0 deletions(-)
 create mode 100644 lenses/resolv.aug
 create mode 100644 lenses/tests/test_resolv.aug

diff --git a/lenses/resolv.aug b/lenses/resolv.aug
new file mode 100644
index 0000000..37b93cc
--- /dev/null
+++ b/lenses/resolv.aug
@@ -0,0 +1,109 @@
+(*
+Module: Resolv
+  Parses /etc/resolv.conf
+
+Author: Raphael Pinson <[email protected]>
+
+About: Reference
+  This lens tries to keep as close as possible to `man resolv.conf` where
possible.
+
+About: Licence
+  This file is licensed under the LGPLv2+, like the rest of Augeas.
+
+About: Lens Usage
+
+About: Configuration files
+  This lens applies to /etc/resolv.conf. See <filter>.
+*)
+
+module Resolv =
+autoload xfm
+
+(************************************************************************
+ * Group:                 USEFUL PRIMITIVES
+ *************************************************************************)
+
+(* View: comment *)
+let comment = Util.comment
+
+(* View: empty *)
+let empty = Util.empty
+
+
+(************************************************************************
+ * Group:                 MAIN OPTIONS
+ *************************************************************************)
+
+(* View: netmask
+A network mask for IP addresses *)
+let netmask = [ label "netmask" . Util.del_str "/" . store Rx.ip ]
+
+(* View: ipaddr
+An IP address or range with an optional mask *)
+let ipaddr = [label "ipaddr" . store Rx.ip . netmask?]
+
+
+(* View: nameserver
+     A nameserver entry *)
+let nameserver = Build.key_value_line
+                    "nameserver" Sep.space (store Rx.ip)
+
+(* View: domain *)
+let domain = Build.key_value_line
+                    "domain" Sep.space (store Rx.word)
+
+(* View: search *)
+let search = Build.key_value_line
+                    "search" Sep.space
+                    (Build.opt_list
+                           [label "domain" . store Rx.word]
+                            Sep.space)
+
+(* View: sortlist *)
+let sortlist = Build.key_value_line
+                    "sortlist" Sep.space
+                    (Build.opt_list
+                           ipaddr
+                           Sep.space)
+
+(************************************************************************
+ * Group:                 SPECIAL OPTIONS
+ *************************************************************************)
+
+(* View: ip6_dotint
+     ip6-dotint option, which supports negation *)
+let ip6_dotint =
+  let negate = [ del "no-" "no-" . label "negate" ]
+    in [ negate? . key "ip6-dotint" ]
+
+(* View: options
+     Options values *)
+let options =
+      let options_entry = Build.key_value ("ndots"|"timeout"|"attempts")
+                                          (Util.del_str ":") (store
Rx.integer)
+                        | Build.flag ("debug"|"rotate"|"no-check-names"
+                                     |"inet6"|"ip6-bytestring"|"edns0")
+                        | ip6_dotint
+
+            in Build.key_value_line
+                    "options" Sep.space
+                    (Build.opt_list
+                           options_entry
+                           Sep.space)
+
+(* View: entry *)
+let entry = nameserver
+          | domain
+          | search
+          | sortlist
+          | options
+
+(* View: lns *)
+let lns = ( empty | comment | entry )*
+
+(* Variable: filter *)
+let filter = (incl "/etc/resolv.conf")
+    . Util.stdexcl
+
+let xfm = transform lns filter
+
diff --git a/lenses/tests/test_resolv.aug b/lenses/tests/test_resolv.aug
new file mode 100644
index 0000000..5e2da3b
--- /dev/null
+++ b/lenses/tests/test_resolv.aug
@@ -0,0 +1,43 @@
+module Test_resolv =
+
+   let conf = "# Sample resolv.conf
+nameserver 192.168.0.3
+nameserver ff02::1
+domain mynet.com
+search mynet.com anotherorg.net
+
+# A sortlist now
+sortlist 130.155.160.0/255.255.240.0 130.155.0.0
+
+options ndots:3 debug timeout:2
+options no-ip6-dotint
+"
+
+test Resolv.lns get conf =
+   { "#comment" = "Sample resolv.conf" }
+   { "nameserver" = "192.168.0.3" }
+   { "nameserver" = "ff02::1" }
+   { "domain" = "mynet.com" }
+   { "search"
+        { "domain" = "mynet.com" }
+        { "domain" = "anotherorg.net" } }
+   {}
+   { "#comment" = "A sortlist now" }
+   { "sortlist"
+        { "ipaddr" = "130.155.160.0"
+           { "netmask" = "255.255.240.0" } }
+        { "ipaddr" = "130.155.0.0" } }
+   {}
+   { "options"
+        { "ndots" = "3" }
+        { "debug" }
+        { "timeout" = "2" } }
+   { "options"
+        { "ip6-dotint"
+             { "negate" } } }
+
+test Resolv.ip6_dotint
+   put "ip6-dotint"
+   after set "/ip6-dotint/negate" "" = "no-ip6-dotint"
+
+
-- 
1.7.0.4
_______________________________________________
augeas-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/augeas-devel

Reply via email to