Imported Upstream version 1.7.0
[platform/upstream/augeas.git] / lenses / lvm.aug
1 (*
2 Module: LVM
3   Parses LVM metadata.
4
5 Author: Gabriel de Perthuis           <g2p.code+augeas@gmail.com>
6
7 About: License
8   This file is licensed under the LGPL v2+.
9
10 About: Configuration files
11   This lens applies to files in /etc/lvm/backup and /etc/lvm/archive.
12
13 About: Examples
14   The <Test_LVM> file contains various examples and tests.
15 *)
16
17 module LVM =
18         autoload xfm
19
20         (* See lvm2/libdm/libdm-config.c for tokenisation;
21          * libdm uses a blacklist but I prefer the safer whitelist approach. *)
22         (* View: identifier
23          * The left hand side of a definition *)
24         let identifier = /[a-zA-Z0-9_-]+/
25
26         (* strings can contain backslash-escaped dquotes, but I don't know
27          * how to get the message across to augeas *)
28         let str = [label "str". Quote.do_dquote (store /([^\"]|\\\\.)*/)]
29         let int = [label "int". store Rx.relinteger]
30         (* View: flat_literal
31          * A literal without structure *)
32         let flat_literal = int|str
33
34         (* allow multiline and mixed int/str, used for raids and stripes *)
35         (* View: list
36          * A list containing flat literals *)
37         let list = [
38                   label "list" . counter "list"
39                 . del /\[[ \t\n]*/ "["
40                 .([seq "list". flat_literal . del /,[ \t\n]*/ ", "]*
41                                 . [seq "list". flat_literal . del /[ \t\n]*/ ""])?
42                 . Util.del_str "]"]
43
44         (* View: val
45          * Any value that appears on the right hand side of an assignment *)
46         let val = flat_literal | list
47
48         (* View: nondef
49          * A line that doesn't contain a statement *)
50         let nondef =
51                   Util.empty
52                 | Util.comment
53
54         (* Build.block couldn't be reused, because of recursion and
55          * a different philosophy of whitespace handling. *)
56         (* View: def
57          * An assignment, or a block containing definitions *)
58         let rec def = [
59                   Util.indent . key identifier . (
60                            del /[ \t]*\{\n/ " {\n"
61                           .[label "dict".(nondef | def)*]
62                           . Util.indent . Util.del_str "}\n"
63                           |Sep.space_equal . val . Util.comment_or_eol)]
64
65         (* View: lns
66          * The main lens *)
67         let lns = (nondef | def)*
68
69         let filter =
70                   incl "/etc/lvm/archive/*.vg"
71                 . incl "/etc/lvm/backup/*"
72                 . incl "/etc/lvm/lvm.conf"
73                 . Util.stdexcl
74
75         let xfm = transform lns filter