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