Imported Upstream version 1.7.0
[platform/upstream/augeas.git] / lenses / sysconfig_route.aug
1 (*
2 Module: Sysconfig_Route
3   Parses /etc/sysconfig/network-scripts/route-${device}
4
5 Author: Stephen P. Schaefer
6
7 About: Reference
8     This lens allows manipulation of *one* IPv4 variant of the
9 /etc/sysconfig/network-scripts/route-${device} script found in RHEL5+, CentOS5+
10 and Fedora.
11
12     The variant handled consists of lines like
13     "destination_subnet/cidr via router_ip", e.g.,
14     "10.132.11.0/24 via 10.10.2.1"
15     
16     There are other variants; if you use them, please enhance this lens.
17     
18     The natural key would be "10.132.11.0/24" with value "10.10.2.1", but since
19     augeas cannot deal with slashes in the key value, I reverse them, so that the
20     key is "10.10.2.1[1]" (and "10.10.2.1[2]"... if multiple subnets are reachable
21     via that router).
22
23 About: License
24    This file is licenced under the LGPL v2+, like the rest of Augeas.
25
26 About: Lens Usage
27   Sample usage of this lens in augtool
28
29     * Set the first subnet reachable by a router reachable on the eth0 subnet
30       > set /files/etc/sysconfig/network-scripts/route-eth0/10.10.2.1[1] 172.16.254.0/24
31     * List all the subnets reachable by a router reachable on eth0 subnet
32       > match /files/etc/sysconfig/network-scripts/route-eth0/10.10.2.1
33
34 About: Configuration files
35   This lens applies to /etc/sysconfig/network-scripts/route-*
36
37 About: Examples
38   The <Test_Sysconfig_Route> file contains various examples and tests.
39 *)
40
41 module Sysconfig_Route =
42         autoload xfm
43
44 (******************************************************************************
45  * Group:                        USEFUL PRIMITIVES
46  ******************************************************************************)
47
48 (* Variable: router
49    A router *)
50 let router = Rx.ipv4
51 (* Variable: cidr
52    A subnet mask can be 0 to 32 bits *)
53 let cidr = /(3[012]|[12][0-9]|[0-9])/
54 (* Variable: subnet
55    Subnet specification *)
56 let subnet = Rx.ipv4 . "/" . cidr
57
58 (******************************************************************************
59  * Group:                        ENTRY TYPES
60  ******************************************************************************)
61
62 (* View: entry
63    One route *)
64 let entry = [ store subnet . del /[ \t]*via[ \t]*/ " via "
65             . key router . Util.del_str "\n" ]
66
67 (******************************************************************************
68  * Group:                        LENS AND FILTER
69  ******************************************************************************)
70
71 (* View: lns *)
72 let lns = entry+
73
74 (* View: filter *)
75 let filter = incl "/etc/sysconfig/network-scripts/route-*"
76            . Util.stdexcl
77
78 let xfm = transform lns filter