Please add the sgi-ipmi plugin

The attached file is the sgi-ipmi plugin.

It supports SGI x86_64 systems based on both Intel and Supermicro BMCs.

Signed-off-by: Russell Coker <[EMAIL PROTECTED]>
Signed-off-by: Ron Kerry <[EMAIL PROTECTED]>
Signed-off-by: Anibal Monsalve Salazar <[EMAIL PROTECTED]>
Signed-off-by: Tim Serong <[EMAIL PROTECTED]>

--- lib/plugins/stonith/external/Makefile.am    2007-12-22 02:32:27.000000000 
+1100
+++ lib/plugins/stonith/external/Makefile.am    2008-05-06 13:21:05.924547054 
+1000
@@ -19,8 +19,8 @@
 #
 MAINTAINERCLEANFILES = Makefile.in
 
-EXTRA_DIST           = ibmrsa-telnet ipmi rackpdu vmware
+EXTRA_DIST           = ibmrsa-telnet ipmi sgi-ipmi rackpdu vmware
 
 extdir              = $(stonith_ext_plugindir)
 
-ext_SCRIPTS         = ibmrsa ibmrsa-telnet ipmi riloe ssh vmware rackpdu
+ext_SCRIPTS         = ibmrsa ibmrsa-telnet ipmi riloe ssh vmware sgi-ipmi 
rackpdu
#!/bin/bash
#
# External STONITH module for ipmi.
# This STONITH module takes two arguments:
#   $1 is the operation
#   $2 is the node to operate on
# It takes a single environmental variable: nodelist
# which is a space separated list of node definitions
# Each Node definition consists of:
#   nodename;userid;passwd;bmctype;ipaddr1[;ipaddrn]
# Where:
#   nodename is the hostname of a node
#   userid   is the userid to use on the IPMI device
#   passwd   is the password to use on the IPMI device
#   bmctype  is the bmctype of the IPMI device (intel or supermicro)
#   ipaddr   is the IP address of the IPMI device
#
# Copyright (c) 2004 SUSE LINUX AG - Lars Marowsky-Bree <[EMAIL PROTECTED]>
# Copyright (c) 2007 Silicon Graphics, Inc. - Russell Coker <[EMAIL PROTECTED]>
# Copyright (c) 2007-2008 Silicon Graphics, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it would be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Further, this software is distributed without any warranty that it is
# free of the rightful claim of any third person regarding infringement
# or the like.  Any license provided herein, whether implied or
# otherwise, applies only to this software file.  Patent licenses, if
# any, provided herein do not apply to combinations of this program with
# other software, or any other product whatsoever.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
#

IPMITOOL=$(which ipmitool 2>/dev/null)
PING=$(which ping 2>/dev/null)

# $1 is the node to operate on
# $2 is the operation
# return 0 on success, 1 on config error, and 2 on IPMI error
doit()
{
    local rc=2

    # Handle operations on myself
    if [ "$1" = "$(hostname)" ]
    then
        case "$2"
        in
            "off")
                /sbin/halt -n
                ;;
            "reset")
                /sbin/reboot -n
                ;;
            "on")
                return 0
                ;;
        esac
        sleep 1
        echo "sgi-ipmi: IPMI module suicide failed" >&2
        return $rc
    fi

    # make sure ipmitool is there
    if [ ! -x "$IPMITOOL" ]
    then
        echo "sgi-ipmi: ipmitool not installed" >&2
        return 1
    fi

    # Take an action on another node
    for nl in $nodelist
    do
        local nln=$nl
        for i in {1..4}
        do
            nln=${nln/;/ }
        done
        local regex="^(.+) (.+) (.+) ([[:alpha:]]+) ([[:digit:].;]+)$"
        if [[ ! "$nln" =~ $regex ]]
        then
            echo "sgi-ipmi: invalid nodelist \"$nl\"; check configuration" >&2
            return 1
        fi
        local host=${BASH_REMATCH[1]}
        local userid=${BASH_REMATCH[2]}
        local passwd=${BASH_REMATCH[3]}
        local bmctype=${BASH_REMATCH[4]}
        local ipaddrs=${BASH_REMATCH[5]}
        ipaddrs=${ipaddrs//;/ }

        if [ "$host" = "$1" ]
        then
            # validate bmctype
            case "$bmctype"
            in
                "intel")
                    local inttype="-I lanplus -o intelplus"
                    ;;
                "supermicro")
                    local inttype="-I lanplus"
                    ;;
                *)
                    echo "sgi-ipmi: bmctype must be intel or supermicro" >&2
                    return 1
                    ;;
            esac

            for ipaddr in ${ipaddrs}
            do
                if $PING -w 3 -c 1 $ipaddr > /dev/null 2>&1
                then
                    echo "sgi-ipmi: no ping response at $ipaddr" >&2
                    continue
                fi

                if $IPMITOOL $inttype -H $ipaddr -U $userid -P $passwd power $2 
> /dev/null 2>&1
                then
                    echo "sgi-ipmi: IPMI $2 for host $1 on $ipaddr succeeded" 
>&2
                    return 0
                else
                    echo "sgi-ipmi: IPMI $2 for host $1 on $ipaddr failed" >&2
                fi
            done

            if [ $rc = 2 ]
            then
                echo "sgi-ipmi: IPMI commands failed for host $1" >&2
            fi

            return $rc
        fi
    done
    echo "sgi-ipmi: Not configured to reset host $1" >&2
    return 1
}

# ----------------------------------------------------------------
# Mainline logic
#
# $1 is the operation
# $2 is the node to operate on
case $1
in
    "gethosts")
        for nl in $nodelist
        do
            echo ${nl%%;*}
        done
        exit 0
        ;;
    "on")
        doit $2 on
        exit $?
        ;;
    "off")
        doit $2 off
        exit $?
        ;;
    "reset")
        if ! doit $2 reset
        then
            doit $2 off
            doit $2 on
        fi
        exit $?
        ;;
    "status")
        if [ -z "$nodelist" ]
        then
            exit 1
        fi
        exit 0
        ;;
    "getconfignames")
        echo "nodelist"
        exit 0
        ;;
    "getinfo-devid")
        echo "SGI IPMI STONITH device"
        exit 0
        ;;
    "getinfo-devname")
        echo "SGI IPMI STONITH external device"
        exit 0
        ;;
    "getinfo-devdescr")
        echo "SGI IPMI multi-port ipmi-based host reset"
        exit 0
        ;;
    "getinfo-devurl")
        echo "http://www.sgi.com/";
        exit 0
        ;;
    "getinfo-xml")
        cat << END
<parameters>
<parameter name="nodelist" unique="1" required="1">
<content type="string" />
<shortdesc lang="en">
Hostlist
</shortdesc>
<longdesc lang="en">
The list of hosts that the STONITH device controls, each host entry
consists of a machine name, an IPMI userid, an IPMI password,
an IPMI bmc type, and a set of IP addresses for the IPMI service
</longdesc>
</parameter>
</parameters>
END
        exit 0
        ;;
    *)
        echo "Bad parameter" >&2
        exit 1
        ;;
esac
_______________________________________________________
Linux-HA-Dev: [email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/

Reply via email to