#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_fabric - Runs show commands for show tech-support fabric
#
# July 2008, Manjusha Namasevi
#
# Copyright (c) 2006-2009 by cisco Systems, Inc.
# All rights reserved.
#--------------------------------------------------------------------
. /pkg/bin/show_tech_main_fragment

location=""
all_cards="location all"

# Depending on single or all nodes specified, set appropriate values
while [ $# -gt 0 ]; do
    case "$1" in
        -L) location="location $2"; all_cards="location $2"; ext_name_valid[1]=0 ; ext_node_name[1]=$2 ; nodeid_valid[1]=0 ; node_name[1]="" ; shift 2;;
        *)  default_parser_function "$@"; shift $#;;
    esac
done

# ****************************************************
# Functions to convert between nodeids and node names
# *****************************************************

# The function strip_nodename takes a nodename in the form net/noder_s_i and
# returns the nodename in the form noder_s_i
#
# Returns: The node name in the form noder_s_i
#
# Argument: The node name in the form net/noder_s_i
strip_nodename(){

    name="$1"
    noder_s_i=${name#*/}
    echo $noder_s_i
}

# Parse /net/*CPU* and get all nodes
if [[ $all_cards = "location all" ]] ; then
    i=1; for node_name[$i] in /net/*CPU*; do
        name[$i]=`strip_nodename ${node_name[$i]}`;
        # The return code (0 on success) from
        # `node_conversion --2nodeid ${node_name[$i]}` is
        # put into the variable node_valid[$i]
        nodeid[$i]=`node_conversion -i ${node_name[$i]}`
        nodeid_valid[$i]=$?
        # The return code (0 on success) from
        # `node_conversion --2extname ${nodeid[$i]}` is
        # put into the variable ext_name_valid[$i]
        ext_node_name[$i]=`node_conversion -e ${nodeid[$i]}`
        ext_name_valid[$i]=$?
        # Prepend a / infront of net/*CPU0*
        node_name[$i]=/${node_name[$i]}
        i=$(($i + 1))
    done
    number_of_nodes=$(($i - 1))
else
    number_of_nodes=1
fi

echo " \n Number of nodes $number_of_nodes"
echo "\n Gathering required commands for show tech fabric in admin mode"
display() {

    # First display list of nodes in the system
    echo "\n Finding available nodes in the system"
    j=1; while [ $j -le $number_of_nodes ]; do
        if [ "${ext_name_valid[j]}" = "0" ] ; then
            nd_name=${ext_node_name[j]}
        else
            nd_name=${name[j]}
        fi
        echo "\n Node - $nd_name"
 
        j=$(($j + 1))
    done;

    print_main_heading 'show tech-support fabric'

    j=1; while [ $j -le $number_of_nodes ]; do
        if [ "${ext_name_valid[j]}" = "0" ] ; then
            nd_name=${ext_node_name[j]}
        else
            nd_name=${name[j]}
        fi

        echo "\n\nLocation: $nd_name"
        location="location $nd_name"

# Place holder to add any admin mode commands 
#       if [ "${nodeid_valid[j]}" = "0" ] ; then
#run_single_command 'admin show controller fabric fia bridge drops $location'
#       fi

        list_of_disks="/disk0:/ /disk1:/"
        list_of_dirs="bcm-cur/ bcm-prev/"
        list_of_files="bcm.log es.log esd.log stp.log stp_shim.log"
        list_of_nums=".0 .1"

        j=$(($j + 1))
    done;

    print_main_heading "show tech-support fabric complete"

}

. /pkg/bin/show_tech_file_fragment


