#!/bin/bash
# Copyright (C) Mellanox Technologies Ltd. 2001-2012.  ALL RIGHTS RESERVED.
#
# This software product is a proprietary product of Mellanox Technologies Ltd.
# (the "Company") and all right, title, and interest in and to the software product,
# including all associated intellectual property rights, are and shall
# remain exclusively with the Company.
#
# This software product is governed by the End User License Agreement
# provided with the software product.

IBPATH=${IBPATH:-/usr/sbin}

function usage() {
    echo Usage: `basename $0` "[-h] [-C ca_name -P ca_port -t(imeout) timeout_ms]"
    exit 1
}

ca_info=""

while [ "$1" ]; do
    case $1 in
    -h)
        usage
        ;;
    -P | -C | -t | -timeout)
        case $2 in
        -*)
            usage
            ;;
        esac
        if [ x$2 = x ] ; then
            usage
        fi
        ca_info="$ca_info $1 $2"
        shift
        ;;
    -*)
        usage
        ;;
    *)
        usage
        ;;
    esac
    shift
done


sm_lid=`sm_info=\`$IBPATH/sminfo $ca_info\` && echo $sm_info | awk '{print $4}'`
if [ $? -eq 0 ]; then
    sm_node_info=`$IBPATH/smpquery $ca_info NodeInfo $sm_lid`
    if [ $? -eq 0 ]; then
        echo "$sm_node_info"
        exit 0
    fi
fi

exit 1
