r1992 + switchvlans and slbconfig gateways now rely on the higher-level RackCode...
[racktables] / gateways / slbconfig / main
CommitLineData
6171ab79
DO
1#!/bin/sh
2
3# This is a RackTables gateway for installing SLB configuration onto
4# a live load balancer. The only supported command is:
5#
6# * connect <endpoint> <hardware> <software> <username>: authorize transaction
d9ec8188 7# * activate <filename>: call user-supplied configuration installer
6171ab79
DO
8#
9
10endpoint=
11hw=
12sw=
13user=
14cfgfile=
15CONNECTED=0
16MYDIR=`dirname $0`
6171ab79
DO
17
18do_connect()
19{
20 endpoint=`echo $args | cut -s -d' ' -f1`
21 hw=`echo $args | cut -s -d' ' -f2`
22 sw=`echo $args | cut -s -d' ' -f3`
23 user=`echo $args | cut -s -d' ' -f4`
24 # sanity checks
25 if [ -z "$endpoint" -o -z "$hw" -o -z "$sw" -o -z "$user" ]; then
26 echo 'ERR!too few arguments to connect'
27 return
28 fi
29
e944af26
DO
30 CONNECTED=1
31 echo "OK!connected to $endpoint"
6171ab79
DO
32}
33
34do_activate()
35{
36 cfgfile=$1
37 if [ ! -s "$cfgfile" ]; then
38 echo "ERR!Configuration file $cfgfile is either missing or empty."
39 return
40 fi
41 if [ ! -x "$MYDIR/install" ]; then
e944af26 42 echo "ERR!Missing or not executable user-supplied installer script $MYDIR/install"
6171ab79
DO
43 return
44 fi
e944af26
DO
45 "$MYDIR/install" $endpoint $hw $sw $user $cfgfile
46 ret=$?
47 if [ $ret = 0 ]; then
48 echo "OK!Configuration has been submitted for activation successfully"
49 else
50 echo "ERR!Configuration installer returned code $ret"
51 fi
6171ab79
DO
52}
53
54# main loop
55while read cmd args; do
56 case $cmd in
57 connect)
58 if [ $CONNECTED = 1 ]; then
59 echo 'ERR!Already connected'
60 else
61 do_connect $args
62 fi
63 ;;
64 activate)
65 if [ $CONNECTED = 1 ]; then
66 do_activate $args
67 else
68 echo 'ERR!Not connected'
69 fi
70 ;;
71 *)
72 echo "ERR!unknown command $cmd"
73 esac
74done
75
6171ab79 76exit 0