r1181 + an ugly, but working VLAN implementation for the real world :)
authorDenis Ovsienko <infrastation@yandex.ru>
Wed, 10 Oct 2007 15:07:27 +0000 (15:07 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Wed, 10 Oct 2007 15:07:27 +0000 (15:07 +0000)
gateways/switchvlans/cisco.connector
gateways/switchvlans/main

index b9bc6ea..2c6ab3a 100755 (executable)
@@ -45,8 +45,55 @@ prepare_fetch_commands()
        printf 'term len 0\nshow int status\nquit\n' >> $CMDS2
 }
 
+# FIXME: this is almost a dup!
 prepare_push_commands()
 {
+       [ $# = 1 ] || exit 1
+       local skip=yes cval
+       while read line; do
+               if [ "$skip" = "yes" -a "$line" = "# S-T-A-R-T" ]; then
+                       skip=no
+                       continue
+               fi
+               if [ "$skip" = "no" -a "$line" = "# S-T-O-P" ]; then
+                       skip=yes
+                       continue
+               fi
+               [ "$skip" = "yes" ] && continue
+               # Allow comments.
+               [ -z "${line###*}" ] && continue
+
+               # First endpoint string/regexp match is sufficient for us.
+               cval=`echo $line | cut -s -d' ' -f1`
+               if [ -z "${1##$cval}" ]; then
+                       # Don't be too smart at the moment, just be able to handle
+                       # the known-good case ;-)
+
+                       echo $line | cut -s -d' ' -f6 > $CMDS1
+                       echo en >> $CMDS1
+                       echo $line | cut -s -d' ' -f7 >> $CMDS1
+
+                       break
+               fi
+       done < `dirname $0`/cisco.secrets.php
+
+
+
+
+       printf 'term len 0\nconf t\n' >> $CMDS1
+       while read portname vlanid; do
+               if [ -z "$portname" -o -z "$vlanid" ]; then
+                       echo "E!could not parse input in connector" >> "$FILE2"
+                       continue
+               fi
+               if [ "$vlanid" = "trunk" ]; then
+                       echo "E!trunking is not allowed" >> "$FILE2"
+                       continue
+               fi
+               printf "int $portname\nswi access vlan $vlanid\nexit\n" >> $CMDS1
+               echo "I!Port $portname@$ENDPOINT has been assigned to VLAN $vlanid" >> "$FILE2"
+       done < "$FILE1"
+       printf "end\nquit\n" >> $CMDS1
 }
 
 do_fetch()
@@ -57,9 +104,10 @@ do_fetch()
 
 do_push()
 {
-       echo "E!this is a stub" >> "$FILE2"
-       echo "W!this is another stub" >> "$FILE2"
-       echo "I!have a good time!" >> "$FILE2"
+       nc $ENDPOINT 23 < $CMDS1 >/dev/null
+#      echo "E!this is a stub" >> "$FILE2"
+#      echo "W!this is another stub" >> "$FILE2"
+#      echo "I!have a good time!" >> "$FILE2"
 }
 
 # This one is for VLAN list.
index e7edddb..cf73147 100755 (executable)
@@ -176,6 +176,7 @@ do_set()
                        echo "E!Port $portname is a trunk" >> "$REPLIES"
                        continue
                fi
+               [ "$curvlan" = "$newvlan" ] && continue
                # Authorize user for each change.
                if ! authorized $endpoint $user change $curvlan $newvlan; then
                        echo "E!User $user is not authorized to assign port $portname@$endpoint from VLAN $curvlan to VLAN $newvlan" >> "$REPLIES"
@@ -185,20 +186,20 @@ do_set()
        done
        nr=`egrep -c '^.' "$REPLIES"`
        if [ "$nr" -ge 1 ]; then
-               echo "W!$nr request(s) have been ignored" >> "$REPLIES"
+               echo "W!$nr change request(s) have been ignored" >> "$REPLIES"
        fi
 
        nq=`egrep -c '^.' "$REQUESTS"`
-       if [ "$nq" -gt 1 ]; then
+       if [ "$nq" -ge 1 ]; then
                # Go!
-               sh -x `dirname $0`/$brand.connector $endpoint push "$REQUESTS" "$REPLIES"
+               `dirname $0`/$brand.connector $endpoint push "$REQUESTS" "$REPLIES"
                local ret=$?
 
                if [ $ret != 0 ]; then
                        echo "ERR!Failed to configure $endpoint, connector returned code $ret"
                        return
                fi
-               echo "I!$nq port(s) have been reconfigured" >> "$REPLIES"
+               echo "I!$nq change request(s) have been processed" >> "$REPLIES"
        fi
        echo -n 'OK!'
        local SEMICOLON=