##############################################################################
# FileName  : GetPoolNameAndPhysicalMem
# Date      : 2014-08-07
# Description   : Check wether the physic memory in one pool as the same
#
##############################################################################

#!/bin/sh

FILE_SNAS_INI="/opt/huawei/snas/etc/snas.ini"
POOL_KEY="nodepool"
G_REMOTE_TMP_FILE="/tmp/tmpfile"
LOG_FILE="/var/log/inspect.log"

tmpLOG=""
tmpBigDirInfo=""

function LOG
{
    time=$(date)
    echo [${time}][$$]$@ >> $LOG_FILE
}

function GetPoolNameAndPhysicalMem
{
    local Result=""
    local tmpPoolName=""
    local tmpPhyMem=""
    local iRet=""

    #Get pool name
    tmpPoolName=`cat $FILE_SNAS_INI | grep -w $POOL_KEY | awk -F = '{printf $2}'`
    iRet=$?
    if [ $iRet -ne 0 ];then
        Result="[ERR]Failed to get pool name from $FILE_SNAS_INI.ERRCODE(5)"
        LOG "Failed to get pool name from $FILE_SNAS_INI"
    else
        tmpPhyMem=`free | grep Mem | awk '{print $2}'`
        iRet=$?
        if [ $iRet -ne 0 ];then
            Result="[ERR]Failed to get physical memory.ERRCODE(6)"
            LOG "Failed to get node physical memory"
        else
            tmpPhyMem=$(expr $tmpPhyMem / 1024)
            Result="$tmpPoolName $tmpPhyMem"
        fi
    fi
    
    echo $Result

}

GetPoolNameAndPhysicalMem

exit 0
