r3325 deviceconfig: renamed cisco.secrets.php to switch.secrets.php
authorDenis Ovsienko <infrastation@yandex.ru>
Thu, 4 Mar 2010 12:31:15 +0000 (12:31 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Thu, 4 Mar 2010 12:31:15 +0000 (12:31 +0000)
deviceconfig: now expect cooked handler as argument instead of hardware and software strings
deviceconfig: cisco.connector becomes ios12.connector
gwRetrieveDeviceConfig(): redo with exceptions
renderObjectVLANSync(): ditto

gateways/deviceconfig/fdry5.connector
gateways/deviceconfig/ios12.connector [moved from gateways/deviceconfig/cisco.connector with 97% similarity]
gateways/deviceconfig/main
gateways/deviceconfig/switch.secrets.php-sample [moved from gateways/deviceconfig/cisco.secrets.php-sample with 100% similarity]
inc/gateways.php
inc/interface.php

index bbc4b5f..cb3e306 100755 (executable)
@@ -36,7 +36,7 @@ prepare_connect_commands()
                        [ "$enable_password" != "-" ] && echo $enable_password >> $CMDS1
                        break
                fi
-       done < "$MYDIR/cisco.secrets.php"
+       done < "$MYDIR/switch.secrets.php"
        [ "$found" = "yes" ] && return
        exit 3
 }
similarity index 97%
rename from gateways/deviceconfig/cisco.connector
rename to gateways/deviceconfig/ios12.connector
index 2933d79..77bc52d 100755 (executable)
@@ -37,7 +37,7 @@ prepare_connect_commands()
                        }
                        break
                fi
-       done < "$MYDIR/cisco.secrets.php"
+       done < "$MYDIR/switch.secrets.php"
        [ "$found" = "yes" ] && return
        exit 3
 }
index 41d8819..ec45f4d 100755 (executable)
@@ -4,8 +4,8 @@
 # equivalent) and prints it onto stdout. When run, it accepts the
 # only command on stdin:
 #
-# * retrieve <endpoint> <outputfile> <hardware> <software>
-#   (save config text into provided file)
+# * retrieve <endpoint> <handler> <outputfile>
+#   (save remote config text into provided local file)
 
 MYDIR=`dirname $0`
 
@@ -45,24 +45,17 @@ decode_error()
 do_work()
 {
        local endpoint=`echo $args | cut -s -d' ' -f1`
-       local conftext=`echo $args | cut -s -d' ' -f2`
-       local hw=`echo $args | cut -s -d' ' -f3`
-       local sw=`echo $args | cut -s -d' ' -f4`
+       local handler=`echo $args | cut -s -d' ' -f2`
+       local conftext=`echo $args | cut -s -d' ' -f3`
        # sanity checks
-       if [ -z "$endpoint" -o -z "$conftext" -o -z "$hw" -o -z "$sw" ]; then
+       if [ -z "$endpoint" -o -z "$conftext" -o -z "$handler" ]; then
                echo 'ERR!too few arguments to connect'
                return
        fi
-       case "$sw" in
-               Cisco+IOS+12.0|Cisco+IOS+12.1|Cisco+IOS+12.2)
-                       local handler=cisco
-               ;;
-               *)
-                       echo "ERR!Don't know how to handle $sw on $endpoint"
-                       return
-               ;;
-       esac
-
+       [ -x "$MYDIR/$handler.connector" ] || {
+               echo "ERR!Handler '$handler' is not available"
+               exit 1
+       }
        "$MYDIR/$handler.connector" $endpoint "$conftext"
        local ret=$?
        if [ $ret = 0 ]; then
index 4e6b983..ea1ec36 100644 (file)
@@ -275,41 +275,57 @@ function gwRecvFileFromObject ($object_id = 0, $handlername, &$output)
        return gwRecvFile ($endpoint, $handlername, $output);
 }
 
-function gwRetrieveDeviceConfig ($object_id = 0, &$output)
+function gwRetrieveDeviceConfig ($object_id = 0)
 {
-       if ($object_id <= 0)
-               return oneLiner (160); // invalid arguments
        $objectInfo = spotEntity ('object', $object_id);
        $endpoints = findAllEndpoints ($object_id, $objectInfo['name']);
        if (count ($endpoints) == 0)
-               return oneLiner (161); // endpoint not found
+               throw new RuntimeException ('endpoint not found');
        if (count ($endpoints) > 1)
-               return oneLiner (162); // can't pick an address
+               throw new RuntimeException ('cannot pick endpoint');
        $endpoint = str_replace (' ', '\ ', str_replace (' ', '+', $endpoints[0]));
-       $tmpfilename = tempnam ('', 'RackTables-sendfile-');
-       $hwtype = $swtype = 'unknown';
+       $tmpfilename = tempnam ('', 'RackTables-deviceconfig-');
+       $breed = '';
        foreach (getAttrValues ($object_id) as $record)
        {
-               if ($record['name'] == 'SW type' && strlen ($record['o_value']))
-                       $swtype = str_replace (' ', '+', execGMarker ($record['o_value']));
-               if ($record['name'] == 'HW type' && strlen ($record['o_value']))
-                       $hwtype = str_replace (' ', '+', execGMarker ($record['o_value']));
+               if
+               (
+                       $record['name'] == 'SW type' &&
+                       strlen ($record['o_value']) &&
+                       preg_match ('/^Cisco IOS 12\./', execGMarker ($record['o_value']))
+               )
+               {
+                       $breed = 'ios12';
+                       break;
+               }
+               if
+               (
+                       $record['name'] == 'HW type' &&
+                       strlen ($record['o_value']) &&
+                       preg_match ('/^Foundry FastIron GS /', execGMarker ($record['o_value']))
+               )
+               {
+                       $breed = 'fdry5';
+                       break;
+               }
        }
+       if ($breed == '')
+               throw new RuntimeException ('cannot pick handler for this device');
        $outputlines = queryGateway
        (
                'deviceconfig',
-               array ("retrieve ${endpoint} ${tmpfilename} ${hwtype} ${swtype}")
+               array ("retrieve ${endpoint} ${breed} ${tmpfilename}")
        );
-       $output = file_get_contents ($tmpfilename);
+       $configtext = file_get_contents ($tmpfilename);
        unlink ($tmpfilename);
        if ($outputlines == NULL)
-               return oneLiner (163); // unknown gateway failure
+               throw new RuntimeException ('unknown gateway failure');
        if (count ($outputlines) != 1)
-               return oneLiner (165); // protocol violation
+               throw new RuntimeException ('gateway protocol violation');
        if (strpos ($outputlines[0], 'OK!') !== 0)
-               return oneLiner (164, array ($outputlines[0])); // gateway failure
-       // Being here means having 'OK!' in the response.
-       return oneLiner (66, array ($handlername)); // ignore provided "Ok" text
+               throw new RuntimeException ("gateway failure: ${outputlines[0]}");
+       // Being here means it was alright.
+       return $configtext;
 }
 
 ?>
index be5e22b..c943a68 100644 (file)
@@ -6864,6 +6864,15 @@ function renderVLANIPv4 ()
 function renderObjectVLANSync ($object_id)
 {
        global $pageno, $tabno, $nextorder;
+       try
+       {
+               $deviceconfig = iosReadVLANConfig (dos2unix (gwRetrieveDeviceConfig ($object_id)));
+       }
+       catch (RuntimeException $re)
+       {
+               showWarning ('Could not retrieve running-config of this device with the following error:<br>' . $re->getMessage(), __FUNCTION__);
+               return;
+       }
        $allowed = getAllowedVLANsForObjectPorts ($object_id);
        $native = getNativeVLANsForObjectPorts ($object_id);
        $object = spotEntity ('object', $object_id);
@@ -6884,9 +6893,6 @@ function renderObjectVLANSync ($object_id)
                                $formports[$port_id]['port_name'] = $port['name'];
                                break;
                        }
-       $rawconf = array();
-       gwRetrieveDeviceConfig ($object_id, $rawconf); // FIXME: handle error
-       $deviceconfig = iosReadVLANConfig (dos2unix ($rawconf));
        foreach ($deviceconfig as $item)
        {
                // map interface name