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