Inital commit
Benjamin Renard

Benjamin Renard commited on 2011-10-27 11:39:59
Showing 2 changed files, with 108 additions and 0 deletions.

... ...
@@ -0,0 +1,21 @@
1
+RouteVia
2
+========
3
+
4
+Description
5
+-----------
6
+
7
+Wrapper of OCF RA Route, based on original heartbeat RA. See OCF RA Route for more information.
8
+
9
+Instalation
10
+-----------
11
+
12
+Put RouteVia script in /etc/ha.d/resource.d/ directory
13
+
14
+Usage
15
+-----
16
+
17
+In haressources file, added :
18
+
19
+node1 RouteVia::172.20.0.0/16/172.24.0.1
20
+
21
+for network 172.20.0.0/16 via 172.24.0.1.
... ...
@@ -0,0 +1,87 @@
1
+#!/bin/bash
2
+#
3
+#
4
+# Description:	wrapper of OCF RA Route, based on original heartbeat RA.
5
+#		See OCF RA Route for more information.
6
+#
7
+# Author:	Benjamin Renard <brenard@easter-eggs.com>
8
+# License:      GNU General Public License (GPL)
9
+# Copyright:	(C) 2011 Easter-eggs
10
+#
11
+#	This script manages IP route via a gateway
12
+#
13
+#	It can add an IP route, or remove one.
14
+#
15
+#	usage: $0 ip-network-destination/netmaskbits/ip-gateway \
16
+#	    {start|stop|status|monitor}
17
+#
18
+#	The "start" arg adds an IP route.
19
+#
20
+#	The "stop" arg removes one.
21
+#
22
+DEBUG=0
23
+
24
+function usage {
25
+	echo "Usage : $0 [-h|--help] route/cidr/via {start|stop|status}"
26
+}
27
+
28
+[ "$1" == "-h" -o "$1" == "--help" ] && usage && exit 0
29
+
30
+config=$1
31
+
32
+function verif_ip {
33
+	ip="$1"
34
+	[ ! -n "$ip" ] && return 1
35
+	[ "$( echo -n "$ip"|sed "s/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*//" )" != "" ] && return 1
36
+	o1=$( echo "$ip"|cut -d'.' -f1 )
37
+	[ "$o1" == "" ] && return 2
38
+	[ $o1 -gt 254 ] && return 2
39
+	o2=$( echo "$ip"|cut -d'.' -f2 )
40
+	[ "$o2" == "" ] && return 3
41
+	[ $o2 -gt 254 ] && return 3
42
+	o3=$( echo "$ip"|cut -d'.' -f3 )
43
+	[ "$o3" == "" ] && return 4
44
+	[ $o3 -gt 254 ] && return 4
45
+	o4=$( echo "$ip"|cut -d'.' -f4 )
46
+	[ "$o4" == "" ] && return 5
47
+	[ $o4 -gt 254 ] && return 5
48
+	return 0
49
+}
50
+
51
+function verif_cidr {
52
+	cidr="$1"
53
+	[ ! -n "$cidr" ] && return 1
54
+	[ "$( echo -n "$cidr"|sed 's/[0-9]*//' )" != '' ] && return 2
55
+	[ $cidr -gt 32 ] && return 3
56
+	return 0
57
+}
58
+
59
+. /etc/ha.d/resource.d//hto-mapfuncs
60
+
61
+# Route
62
+route=$( echo "$config"|cut -d'/' -f1 )
63
+[ $DEBUG -eq 1 ] && echo "Route : $route"
64
+verif_ip "$route"
65
+res=$?
66
+[ $res -ne 0 ] &&  echo "[ERROR] Route is not valid" && usage && exit $res 
67
+
68
+# CIDR
69
+cidr=$( echo "$config"|cut -d'/' -f2 )
70
+[ $DEBUG -eq 1 ] && echo "CIDR : $cidr"
71
+verif_cidr "$cidr"
72
+res=$?
73
+[ $res -ne 0 ] &&  echo "[ERROR] CIDR is not valid" && usage && exit $res 
74
+export OCF_RESKEY_destination="$route/$cidr"
75
+
76
+# Via
77
+via=$( echo "$config"|cut -d'/' -f3 )
78
+[ $DEBUG -eq 1 ] && echo "Via : $via"
79
+verif_ip "$via"
80
+res=$?
81
+[ $res -ne 0 ] &&  echo "[ERROR] Via host is not valid" && usage && exit $res 
82
+export OCF_RESKEY_gateway="$via"
83
+
84
+export OCF_TYPE=Route
85
+export OCF_RESOURCE_INSTANCE=${OCF_TYPE}_${OCF_RESKEY_destination}_${OCF_RESKEY_gateway}
86
+
87
+ra_execocf $2
0 88