r4324 added RHEL6
[racktables] / gateways / deviceconfig / ios12.connector
CommitLineData
c3c849f3
DO
1#!/bin/sh
2
a1be4d75 3[ $# = 3 ] || exit 1
c3c849f3
DO
4
5ENDPOINT=$1
a1be4d75
DO
6COMMAND=$2
7WORKFILE=$3
c3c849f3
DO
8
9prepare_connect_commands()
10{
11 [ $# = 1 ] || exit 2
9b9ba1bc 12 local skip=yes cval found=no MYDIR=`dirname $0`
c3c849f3
DO
13 while read line; do
14 if [ "$skip" = "yes" -a "$line" = "# S-T-A-R-T" ]; then
15 skip=no
16 continue
17 fi
18 if [ "$skip" = "no" -a "$line" = "# S-T-O-P" ]; then
19 skip=yes
20 continue
21 fi
22 [ "$skip" = "yes" ] && continue
9b9ba1bc 23 # ignore comments
c3c849f3
DO
24 [ -z "${line###*}" ] && continue
25
26 # First endpoint string/regexp match is sufficient for us.
27 cval=`echo $line | cut -s -d' ' -f1`
28 if [ -z "${1##$cval}" ]; then
29 found=yes
c3c849f3 30 username=`echo $line | cut -s -d' ' -f5`
a1be4d75 31 [ "$username" != "-" ] && echo $username > $SESSION
c3c849f3 32 # access password
a1be4d75 33 echo $line | cut -s -d' ' -f6 >> $SESSION
c3c849f3
DO
34 enable_password=`echo $line | cut -s -d' ' -f7`
35 [ "$enable_password" != "-" ] && {
a1be4d75
DO
36 echo en >> $SESSION
37 echo $enable_password >> $SESSION
c3c849f3 38 }
c3c849f3
DO
39 break
40 fi
0f86f02c 41 done < "$MYDIR/switch.secrets.php"
c3c849f3 42 [ "$found" = "yes" ] && return
c3c849f3
DO
43 exit 3
44}
45
64701a49 46MYNAME=`basename $0`
bbd417bd 47SESSION=`mktemp /tmp/$MYNAME.XXXXXX`
a1be4d75 48[ -f "$SESSION" ] || exit 5
9b9ba1bc 49prepare_connect_commands $ENDPOINT
a1be4d75 50case $COMMAND in
db64180c 51get8021q)
a1be4d75
DO
52 printf 'term len 0\nshow run\n! END OF CONFIG\nshow vlan brief\n! END OF VLAN LIST\n' >> "$SESSION"
53 outfile="$WORKFILE"
54 ;;
e9d357e1
DO
55getcdpstatus)
56 printf 'term len 0\nshow cdp neighbors detail\n' >> "$SESSION"
57 outfile="$WORKFILE"
58 ;;
1ebbf889
AA
59getlldpstatus)
60 printf 'term len 0\nshow lldp neighbors\n' >> "$SESSION"
61 outfile="$WORKFILE"
62 ;;
65e557dd
AA
63getportstatus)
64 printf 'term len 0\nshow int status\n' >> "$SESSION"
65 outfile="$WORKFILE"
66 ;;
67getmaclist)
68 printf 'term len 0\nshow mac address-table dynamic\n' >> "$SESSION"
69 outfile="$WORKFILE"
70 ;;
a1be4d75
DO
71deploy)
72 cat "$WORKFILE" >> "$SESSION"
73 outfile=/dev/null
74 ;;
75*)
64701a49
DO
76 rm -f "$SESSION"
77 exit 6
a1be4d75
DO
78 ;;
79esac
80printf 'quit\n' >> "$SESSION"
64701a49
DO
81rc=0
82nc -w 30 $ENDPOINT 23 < "$SESSION" > "$outfile" || rc=4
a1be4d75 83rm -f "$SESSION"
64701a49 84exit $rc