Blame lenses/redis.aug

Packit Service a2ae7a
(*
Packit Service a2ae7a
Module: Redis
Packit Service a2ae7a
  Parses Redis's configuration files
Packit Service a2ae7a
Packit Service a2ae7a
Author: Marc Fournier <marc.fournier@camptocamp.com>
Packit Service a2ae7a
Packit Service a2ae7a
About: Reference
Packit Service a2ae7a
    This lens is based on Redis's default redis.conf
Packit Service a2ae7a
Packit Service a2ae7a
About: Usage Example
Packit Service a2ae7a
(start code)
Packit Service a2ae7a
augtool> set /augeas/load/Redis/incl "/etc/redis/redis.conf"
Packit Service a2ae7a
augtool> set /augeas/load/Redis/lens "Redis.lns"
Packit Service a2ae7a
augtool> load
Packit Service a2ae7a
Packit Service a2ae7a
augtool> get /files/etc/redis/redis.conf/vm-enabled
Packit Service a2ae7a
/files/etc/redis/redis.conf/vm-enabled = no
Packit Service a2ae7a
augtool> print /files/etc/redis/redis.conf/rename-command[1]/
Packit Service a2ae7a
/files/etc/redis/redis.conf/rename-command
Packit Service a2ae7a
/files/etc/redis/redis.conf/rename-command/from = "CONFIG"
Packit Service a2ae7a
/files/etc/redis/redis.conf/rename-command/to = "CONFIG2"
Packit Service a2ae7a
Packit Service a2ae7a
augtool> set /files/etc/redis/redis.conf/activerehashing no
Packit Service a2ae7a
augtool> save
Packit Service a2ae7a
Saved 1 file(s)
Packit Service a2ae7a
augtool> set /files/etc/redis/redis.conf/save[1]/seconds 123
Packit Service a2ae7a
augtool> set /files/etc/redis/redis.conf/save[1]/keys 456
Packit Service a2ae7a
augtool> save
Packit Service a2ae7a
Saved 1 file(s)
Packit Service a2ae7a
(end code)
Packit Service a2ae7a
   The <Test_Redis> file also contains various examples.
Packit Service a2ae7a
Packit Service a2ae7a
About: License
Packit Service a2ae7a
  This file is licensed under the LGPL v2+, like the rest of Augeas.
Packit Service a2ae7a
*)
Packit Service a2ae7a
Packit Service a2ae7a
module Redis =
Packit Service a2ae7a
autoload xfm
Packit Service a2ae7a
Packit Service a2ae7a
let k = Rx.word
Packit Service a2ae7a
let v = /[^ \t\n'"]+/
Packit Service a2ae7a
let comment = Util.comment
Packit Service a2ae7a
let empty = Util.empty
Packit Service a2ae7a
let indent = Util.indent
Packit Service a2ae7a
let eol = Util.eol
Packit Service a2ae7a
let del_ws_spc = Util.del_ws_spc
Packit Service a2ae7a
let dquote = Util.del_str "\""
Packit Service a2ae7a
Packit Service a2ae7a
(* View: standard_entry
Packit Service a2ae7a
A standard entry is a key-value pair, separated by blank space, with optional
Packit Service a2ae7a
blank spaces at line beginning & end. The value part can be optionnaly enclosed
Packit Service a2ae7a
in single or double quotes. Comments at end-of-line ar NOT allowed by
Packit Service a2ae7a
redis-server.
Packit Service a2ae7a
*)
Packit Service a2ae7a
let standard_entry =
Packit Service a2ae7a
     let reserved_k = "save" | "rename-command" | "slaveof"
Packit Service a2ae7a
                    | "bind" | "client-output-buffer-limit"
Packit Service a2ae7a
  in let entry_noempty = [ indent . key (k - reserved_k) . del_ws_spc
Packit Service a2ae7a
                         . Quote.do_quote_opt_nil (store v) . eol ]
Packit Service a2ae7a
  in let entry_empty = [ indent . key (k - reserved_k) . del_ws_spc
Packit Service a2ae7a
                         . dquote . store "" . dquote . eol ]
Packit Service a2ae7a
  in entry_noempty | entry_empty
Packit Service a2ae7a
Packit Service a2ae7a
let save = /save/
Packit Service a2ae7a
let seconds = [ label "seconds" . Quote.do_quote_opt_nil (store Rx.integer) ]
Packit Service a2ae7a
let keys = [ label "keys" . Quote.do_quote_opt_nil (store Rx.integer) ]
Packit Service a2ae7a
(* View: save_entry
Packit Service a2ae7a
Entries identified by the "save" keyword can be found more than once. They have
Packit Service a2ae7a
2 mandatory parameters, both integers. The same rules as standard_entry apply
Packit Service a2ae7a
for quoting, comments and whitespaces.
Packit Service a2ae7a
*)
Packit Service a2ae7a
let save_entry = [ indent . key save . del_ws_spc . seconds . del_ws_spc . keys . eol ]
Packit Service a2ae7a
Packit Service a2ae7a
let slaveof = /slaveof/
Packit Service a2ae7a
let ip = [ label "ip" . Quote.do_quote_opt_nil (store Rx.ip) ]
Packit Service a2ae7a
let port = [ label "port" . Quote.do_quote_opt_nil (store Rx.integer) ]
Packit Service a2ae7a
(* View: slaveof_entry
Packit Service a2ae7a
Entries identified by the "slaveof" keyword can be found more than once. They
Packit Service a2ae7a
have 2 mandatory parameters, the 1st one is an IP address, the 2nd one is a
Packit Service a2ae7a
port number. The same rules as standard_entry apply for quoting, comments and
Packit Service a2ae7a
whitespaces.
Packit Service a2ae7a
*)
Packit Service a2ae7a
let slaveof_entry = [ indent . key slaveof . del_ws_spc . ip . del_ws_spc . port . eol ]
Packit Service a2ae7a
Packit Service a2ae7a
(* View: bind_entry
Packit Service a2ae7a
The "bind" entry can be passed one or several ip addresses. A bind
Packit Service a2ae7a
statement "bind ip1 ip2 .. ipn" results in a tree
Packit Service a2ae7a
{ "bind" { "ip" = ip1 } { "ip" = ip2 } ... { "ip" = ipn } }
Packit Service a2ae7a
*)
Packit Service a2ae7a
let bind_entry =
Packit Service a2ae7a
  let ip = del_ws_spc . Quote.do_quote_opt_nil (store Rx.ip) in
Packit Service a2ae7a
  indent . [ key "bind" . [ label "ip" . ip ]+ ] . eol
Packit Service a2ae7a
Packit Service a2ae7a
let renamecmd = /rename-command/
Packit Service a2ae7a
let from = [ label "from" . Quote.do_quote_opt_nil (store Rx.word) ]
Packit Service a2ae7a
let to = [ label "to" . Quote.do_quote_opt_nil (store Rx.word) ]
Packit Service a2ae7a
(* View: save_entry
Packit Service a2ae7a
Entries identified by the "rename-command" keyword can be found more than once.
Packit Service a2ae7a
They have 2 mandatory parameters, both strings. The same rules as
Packit Service a2ae7a
standard_entry apply for quoting, comments and whitespaces.
Packit Service a2ae7a
*)
Packit Service a2ae7a
let renamecmd_entry = [ indent . key renamecmd . del_ws_spc . from . del_ws_spc . to . eol ]
Packit Service a2ae7a
Packit Service a2ae7a
let cobl_cmd = /client-output-buffer-limit/
Packit Service a2ae7a
let class = [ label "class" . Quote.do_quote_opt_nil (store Rx.word) ]
Packit Service a2ae7a
let hard_limit = [ label "hard_limit" . Quote.do_quote_opt_nil (store Rx.word) ]
Packit Service a2ae7a
let soft_limit = [ label "soft_limit" . Quote.do_quote_opt_nil (store Rx.word) ]
Packit Service a2ae7a
let soft_seconds = [ label "soft_seconds" . Quote.do_quote_opt_nil (store Rx.integer) ]
Packit Service a2ae7a
(* View: client_output_buffer_limit_entry
Packit Service a2ae7a
Entries identified by the "client-output-buffer-limit" keyword can be found
Packit Service a2ae7a
more than once. They have four mandatory parameters, of which the first is a
Packit Service a2ae7a
string, the last one is an integer and the others are either integers or words,
Packit Service a2ae7a
although redis is very liberal and takes "4242yadayadabytes" as a valid limit.
Packit Service a2ae7a
The same rules as standard_entry apply for quoting, comments and whitespaces.
Packit Service a2ae7a
*)
Packit Service a2ae7a
let client_output_buffer_limit_entry =
Packit Service a2ae7a
  [ indent . key cobl_cmd . del_ws_spc . class . del_ws_spc . hard_limit .
Packit Service a2ae7a
    del_ws_spc . soft_limit . del_ws_spc . soft_seconds . eol ]
Packit Service a2ae7a
Packit Service a2ae7a
let entry = standard_entry
Packit Service a2ae7a
          | save_entry
Packit Service a2ae7a
	  | renamecmd_entry
Packit Service a2ae7a
	  | slaveof_entry
Packit Service a2ae7a
	  | bind_entry
Packit Service a2ae7a
	  | client_output_buffer_limit_entry
Packit Service a2ae7a
Packit Service a2ae7a
(* View: lns
Packit Service a2ae7a
The Redis lens
Packit Service a2ae7a
*)
Packit Service a2ae7a
let lns = (comment | empty | entry )*
Packit Service a2ae7a
Packit Service a2ae7a
let filter = incl "/etc/redis/redis.conf"
Packit Service a2ae7a
Packit Service a2ae7a
let xfm = transform lns filter