ctdb-tests: Create 13.per_ip_routing.sh
[metze/samba/wip.git] / ctdb / tests / eventscripts / scripts / 13.per_ip_routing.sh
1 setup_ctdb_policy_routing ()
2 {
3         service_name="per_ip_routing"
4
5         export CTDB_PER_IP_ROUTING_CONF="$CTDB_BASE/policy_routing"
6         export CTDB_PER_IP_ROUTING_RULE_PREF=100
7         export CTDB_PER_IP_ROUTING_TABLE_ID_LOW=1000
8         export CTDB_PER_IP_ROUTING_TABLE_ID_HIGH=2000
9
10         # Tests need to create and populate this file
11         rm -f "$CTDB_PER_IP_ROUTING_CONF"
12 }
13
14 # Create policy routing configuration in $CTDB_PER_IP_ROUTING_CONF.
15 # $1 is the number of assigned IPs to use (<num>, all), defaulting to
16 # 1.  If $2 is "default" then a default route is also added.
17 create_policy_routing_config ()
18 {
19         _num_ips="${1:-1}"
20         _should_add_default="$2"
21
22         ctdb_get_my_public_addresses |
23         if [ "$_num_ips" = "all" ] ; then
24                 cat
25         else
26                 { head -n "$_num_ips" ; cat >/dev/null ; }
27         fi |
28         while read _dev _ip _bits ; do
29                 _net=$(ipv4_host_addr_to_net "$_ip" "$_bits")
30                 _gw="${_net%.*}.254" # a dumb, calculated default
31
32                 echo "$_ip $_net"
33
34                 if [ "$_should_add_default" = "default" ] ; then
35                         echo "$_ip 0.0.0.0/0 $_gw"
36                 fi
37         done >"$CTDB_PER_IP_ROUTING_CONF"
38 }