r4324 added RHEL6
[racktables] / gateways / deviceconfig / main
1 #!/bin/sh
2
3 # This gateway retrieves the output of "show run" command (or its
4 # equivalent) and prints it onto stdout. When run, it accepts the
5 # following commands on stdin:
6 #
7 # * get8021q <endpoint> <handler> <outputfile>
8 # (save remote config text into provided local file)
9 #
10 # * getcdpstatus <endpoint> <handler> <outputfile>
11 # (save remote status text into provided local file)
12 #
13 # * deploy <endpoint> <handler> <inputfile>
14 # (execute given text in privileged mode)
15
16 MYDIR=`dirname $0`
17
18 decode_error()
19 {
20 case "$1" in
21 1)
22 echo -n 'invalid connector args'
23 ;;
24 2)
25 echo -n 'internal error 2'
26 ;;
27 3)
28 echo -n 'password not found'
29 ;;
30 4)
31 echo -n 'netcat failed'
32 ;;
33 5)
34 echo -n 'cannot create temporary files'
35 ;;
36 6)
37 echo -n 'command not supported by device'
38 ;;
39 *)
40 echo -n "unknown error $1"
41 ;;
42 esac
43 }
44
45 while read command endpoint handler conftext; do
46 # sanity checks
47 if [ -z "$endpoint" -o -z "$conftext" -o -z "$handler" -o -z "$command" ]; then
48 echo 'ERR!too few arguments in command'
49 return
50 fi
51 [ -x "$MYDIR/$handler.connector" ] || {
52 echo "ERR!Connector '$handler' is not available"
53 exit 1
54 }
55 "$MYDIR/$handler.connector" $endpoint $command "$conftext"
56 ret=$?
57 if [ $ret = 0 ]; then
58 echo "OK!request '$command' complete for $endpoint"
59 else
60 echo -n "ERR!connector error ("
61 decode_error $ret
62 echo ')'
63 fi
64 done
65
66 # all error messages have been sent to stdout
67 exit 0