On 10/18/2012 01:02 AM, Zdenek Styblik wrote: > On Mon, Oct 8, 2012 at 8:19 AM, <charles_r...@dell.com> wrote: > [...] >>> A startup script that can do these: >>> >>> 1. Set OS Name, Version, System Hostname in BMC >>> 2. Get BMC URL/IP address from BMC >>> >>> Would benefit: >>> 1. users who would like to fetch hostname/OS Name/Version. >>> 2. launch web-interface to BMC where supported with "xdg-open $BMC_URL" >>> 3. Use the BMC_IP for other purposes like >>> 3a. snmp proxy from host to BMC when BMC agent present. >>> 3b. expose BMC IP/URL via other systems management interfaces (like >>> wsman). >>> >>> ---------------------------------------------------------------------- >>> >> Hello, >> >> I request feedback on this proposal that will help users who would like >> certain pieces of OS/BMC >> information set during system start-up. >> >> Here is a start-up script that implements this proposal: >> >> http://sourceforge.net/tracker/?func=detail&aid=3571446&group_id=95200&atid=610552 >> > > Hi Charles, > > at first, I wanted to say I see no problem with committing this > script. And I still don't in general. However ... > > Is this script useful to somebody else than Dell customers running > RHEL-based distribution?
Zdenek, There are four pieces of information that are exchanged here: 1. OS Name - this is a standard IPMI command 2. OS Hostname - this is a standard IPMI command 3. OS Version - this is a delloem command. The script has provision to include other OEMs if they support this command. 5. BMC IP - this is a standard IPMI command 6. BMC URL - this is a delloem command. Although, on non-dell systems, this would simply be "https://$BMC_IP:443" So, with the exception of #3, all of them should work on any system that supports the respective commands. While I developed these for RHEL, I would like to have this working on popular Linux distros. I will include a debian and suse version of the script soon (one this one is accepted). There is a systemd unit coming up as well. > > Some Bashisms in the script: > ~~~ > bash-4.2$ perl checkbashisms exchange-bmc-os-info.sh > possible bashism in exchange-bmc-os-info.sh line 206 ($"foo" should be > eval_gettext "foo"): > echo -n $"${SCRIPT_NAME}: " > possible bashism in exchange-bmc-os-info.sh line 210 ($"foo" should be > eval_gettext "foo"): > echo $"BMC info not available" > possible bashism in exchange-bmc-os-info.sh line 218 ($"foo" should be > eval_gettext "foo"): > echo $"Usage: $0 {start|stop|restart|reload|status}" 1>&2 > possible bashism in exchange-bmc-os-info.sh line 235 ($"foo" should be > eval_gettext "foo"): > 2) echo $"${SCRIPT_NAME}: failed to communicate with BMC" 1>&2 ;; > possible bashism in exchange-bmc-os-info.sh line 236 ($"foo" should be > eval_gettext "foo"): > 3) echo $"${SCRIPT_NAME}: failed to set OS information in BMC" 1>&2 ;; > possible bashism in exchange-bmc-os-info.sh line 237 ($"foo" should be > eval_gettext "foo"): > 4) echo $"${SCRIPT_NAME}: failed to get BMC information" 1>&2 ;; > ~~~ > > I especially "urge" to replace % echo -n; with appropriate % printf ; > Since "${SCRIPT_NAME} ..." is first, I'd write it as % echo -- > "${SCRIPT_NAME} ..." just to be sure. > What if $RETVAL is something unexpected? Currently only values of > $RETVAL from 2-4 are covered. Unexpected $RETVAL should produce > something like % printf "%s: unexpected error. Return code: %s." > "${SCRIPT_NAME}" "${RETVAL}" > Please, clean up trailing tabs and spaces. > > ~~~ > set_bmc_info() > { > touch ${BMC_INFO} && chmod 600 ${BMC_INFO} && \ > { > echo "BMC_IPv4=${BMC_IPv4}" > echo "BMC_URL=${BMC_URL}" > } > ${BMC_INFO} || \ > RETVAL=4 > } > ~~~ > > Rewritten as: > ~~~set_bmc_info() > { > touch "${BMC_INFO}" && chmod 600 "${BMC_INFO}" && \ > printf "BMC_IPv4=${BMC_IPv4}\nBMC_URL=${BMC_URL}" > > "${BMC_INFO}" || \ > RETVAL=4 > } > ~~~ > > Can something like this: > ~~~ > if [ -z "${BMC_IPv4}" -o "${BMC_IPv4}" = "0.0.0.0" ]; then > ~~~ > > be rewritten as: > ~~~ > if [ -z "${BMC_IPv4}" ] || [ "${BMC_IPv4}" = "0.0.0.0" ]; then > ~~~ > ? > > Or just have /bin/bash at shebang ;) > I'd also put "..." around variables wherever possible, although that's > my paranoia talking. > > I hope you'll receive this sort of criticism ... "well"(?). Thanks for reviewing this and for the feedback. Here is an updated patch that incorporates your feedback and few other clean ups as well. diff -Nru ipmitool-1_8_12.orig/contrib/exchange-bmc-os-info.redhat ipmitool-1_8_12/contrib/exchange-bmc-os-info.redhat --- ipmitool-1_8_12.orig/contrib/exchange-bmc-os-info.redhat 1970-01-01 05:30:00.000000000 +0530 +++ ipmitool-1_8_12/contrib/exchange-bmc-os-info.redhat 2012-10-18 16:01:13.230345950 +0530 @@ -0,0 +1,249 @@ +#!/bin/sh +B +############################################################################# +# +# exchange-bmc-os-info: Set OS and BMC (Baseboard Management Controller) +# parameters during system startup. +# +# Authors: Charles Rose <charles_r...@dell.com> +# Jordan Hargrave <jordan_hargr...@dell.com> +# +# Description: Script to set OS information in the BMC; fetch BMC IP/URL +# and set in the OS for use by other scripts/user. +# +# BMC IP and URL are made available in /run/bmc-info +# +# Example to launch BMC web-interface: +# # . /run/bmc-info +# # xdg-open $BMC_URL +# +# See here for details: +# https://fedoraproject.org/wiki/Features/AgentFreeManagement +# +############################################################################# +# +# chkconfig: 345 99 00 +# description: Set OS name, hostname in BMC; make BMC IP/URL available in OS +# processname: exchange-bmc-os-info +# config: /etc/sysconfig/exchange-bmc-os-info +# +### BEGIN INIT INFO +# Provides: exchange-bmc-os-info +# Required-Start: ipmi +# Default-Start: 3 4 5 +# Default-Stop: 0 1 2 6 + + +############################################################################# +# GLOBALS +############################################################################# +CONFIGFILE=/etc/sysconfig/exchange-bmc-os-info +IPMI_TOOL=/usr/bin/ipmitool +BMC_INFO=/run/bmc-info + +# BMC Manufacturer ID. Required for ipmi oem commands +DELL="674" +#OTHER_OEM="123" + +# Defaults for ${CONFIGFILE} +SET_OS_INFO="no" +RESET_OS_INFO="yes" +SET_BMC_INFO="no" + +# IPMI commands +IPMI_SET_SYSINFO="${IPMI_TOOL} mc setsysinfo" +IPMI_GET_SYSINFO="${IPMI_TOOL} mc getsysinfo" +############################################################################# + +SCRIPT_NAME=$(basename $0) +# source config +[ -r ${CONFIGFILE} ] && . ${CONFIGFILE} + +RETVAL=0 + +. gettext.sh + +bmc_exists() +{ + # We should be able to execute ipmi commands + [ -x "${IPMI_TOOL}" ] && \ + BMC_VENDOR=$(${IPMI_TOOL} mc info 2>/dev/null | \ + sed -n "s#^Manufacturer ID.*: ##p") + if [ -z "${BMC_VENDOR}" ]; then + # we assume ipmitool failed + return 1 + fi +} +############################################################################# + +get_os_info() +{ + OS_HOSTNAME=$(hostname) + KERNEL_VERSION=$(uname -r -m) + + if [ -e /etc/lsb-release ] ; then + . /etc/lsb-release + NAME=${DISTRIB_ID} + VERSION="${DISTRIB_RELEASE} ${DISTRIB_CODENAME}" + fi + + # we prefer systemd's /etc/os-release over other sources + [ -e /etc/os-release ] && . /etc/os-release + + OS_NAME=${NAME} + OS_VERSION="${VERSION} kernel ${KERNEL_VERSION}" +} + +set_os_version() +{ + # OS Version setting is not standard yet + # we need per vendor oem commands + case "${BMC_VENDOR}" in + ${DELL}) ${IPMI_SET_SYSINFO} delloem_os_version \ + "${OS_VERSION}" > /dev/null 2>&1 + return $? + ;; + *) return 1 + ;; + esac +} + +set_os_info () +{ + # Set and reset OS info in the BMC + if [ "$1" = "reset" ]; then + OS_NAME="" + OS_HOSTNAME="" + OS_VERSION="" + fi + + ${IPMI_SET_SYSINFO} os_name ${OS_NAME} >/dev/null 2>&1 \ + || RETVAL=3 + ${IPMI_SET_SYSINFO} primary_os_name ${OS_NAME} >/dev/null 2>&1 \ + || RETVAL=3 + ${IPMI_SET_SYSINFO} system_name ${OS_HOSTNAME} >/dev/null 2>&1 \ + || RETVAL=3 + set_os_version || RETVAL=3 +} + +############################################################################# +get_bmc_url() +{ + # BMC URL is not standard yet + # we need per vendor oem commands + case "$BMC_VENDOR" in + $DELL) ${IPMI_GET_SYSINFO} delloem_url > /dev/null 2>&1 + ;; + *) echo ;; + esac +} + +get_bmc_info() +{ + # Get BMC_IPv4 and BMC_URL from BMC + BMC_IPv4=$(${IPMI_TOOL} lan print 1 2>/dev/null \ + | sed -n "s#^IP Address .*: ##p") + if [ -z "${BMC_IPv4}" ] || [ "${BMC_IPv4}" = "0.0.0.0" ]; then + BMC_IPv4="" + RETVAL=4 + else + # URL makes sense only if there is an IP + BMC_URL=$(get_bmc_url) + [ -z "${BMC_URL}" ] && BMC_URL="https://${BMC_IPv4}:443" + fi +} + +set_bmc_info() +{ + touch "${BMC_INFO}" && chmod 600 "${BMC_INFO}" && \ + printf "BMC_IPv4=%s\nBMC_URL=%s" "${BMC_IPv4}" "${BMC_URL}" > \ + "${BMC_INFO}" || \ + RETVAL=4 +} + +unset_bmc_info() +{ + [ -f ${BMC_INFO} ] && rm -f ${BMC_INFO} \ + > /dev/null 2>&1 +} + +############################################################################# +start() +{ + if bmc_exists; then + [ "${SET_OS_INFO}" = "yes" ] && \ + get_os_info && set_os_info + + if [ "${SET_BMC_INFO}" = "yes" ]; then + get_bmc_info + if [ ${RETVAL} -eq 0 ]; then + set_bmc_info + fi + fi + else + RETVAL=2 + fi +} + +############################################################################# +stop() +{ + if bmc_exists; then + # reset OS info while system reboots + # aids with debugging OS boot-up issues + if [ "${RESET_OS_INFO}" = "yes" ]; then + set_os_info reset + fi + unset_bmc_info + else + RETVAL=2 + fi +} + +############################################################################# +status() +{ + eval_gettext "${SCRIPT_NAME}: " + if [ -r ${BMC_INFO} ]; then + bmc_url_out=$(grep "BMC_URL" ${BMC_INFO} 2>/dev/null) + printf "%s\n" "${bmc_url_out}" + else + eval_gettext "BMC info unavailable"; echo + fi + RETVAL=0 +} + +############################################################################# +usage() +{ + eval_gettext "Usage: $0 {start|stop|restart|reload|status}"; echo 1>&2 + RETVAL=1 +} + +############################################################################# +# MAIN +############################################################################# +case "$1" in + start) start ;; + stop) stop ;; + restart) start ;; + reload) start ;; + status) status ;; + *) usage ;; +esac + +case "$RETVAL" in + 0|1) ;; + 2) eval_gettext "${SCRIPT_NAME}: failed to communicate with BMC." 1>&2 ;; + 3) eval_gettext "${SCRIPT_NAME}: failed to set OS information in BMC." 1>&2 ;; + 4) eval_gettext "${SCRIPT_NAME}: failed to get BMC information." 1>&2 ;; + *) eval_gettext "${SCRIPT_NAME}: unexpected error." 1>&2 ;; +esac + +if [ ${RETVAL} -gt 1 ]; then + eval_gettext " Return code: ${RETVAL}"; echo +fi +exit ${RETVAL} + +############################################################################# +# end of file +############################################################################# diff -Nru ipmitool-1_8_12.orig/contrib/exchange-bmc-os-info.sysconf ipmitool-1_8_12/contrib/exchange-bmc-os-info.sysconf --- ipmitool-1_8_12.orig/contrib/exchange-bmc-os-info.sysconf 1970-01-01 05:30:00.000000000 +0530 +++ ipmitool-1_8_12/contrib/exchange-bmc-os-info.sysconf 2012-10-18 16:03:01.014077697 +0530 @@ -0,0 +1,13 @@ +# exchange-bmc-os-info +# +# Config file to control Exchange of information between +# the OS and Service Processor/Baseboard Management Controller (BMC) +# + +### Set OS Info in BMC/Service Processor ### +# Set OS Name, Version and Hostname in the Service Processor (BMC) +SET_OS_INFO="yes" + +### Set BMC/Service Processor Info in OS ### +# Get IP Address and URL of Service Processor/BMC +SET_BMC_INFO="yes" diff -Nru ipmitool-1_8_12.orig/contrib/Makefile.am ipmitool-1_8_12/contrib/Makefile.am --- ipmitool-1_8_12.orig/contrib/Makefile.am 2008-07-11 05:03:13.000000000 +0530 +++ ipmitool-1_8_12/contrib/Makefile.am 2012-10-18 16:02:17.336781081 +0530 @@ -35,5 +35,6 @@ EXTRA_DIST = README \ bmclanconf ipmi.init.basic ipmi.init.redhat \ ipmievd.init.redhat ipmievd.init.suse ipmievd.init.debian \ + exchange-bmc-os-info.redhat exchange-bmc-os-info.sysconf \ collect_data.sh create_rrds.sh create_webpage_compact.sh create_webpage.sh > > Regards, > Z. > >> >> -- >> Charles Rose >> Linux Engineering >> Dell Inc. >> ------------------------------------------------------------------------------ >> Don't let slow site performance ruin your business. Deploy New Relic APM >> Deploy New Relic app performance management and know exactly >> what is happening inside your Ruby, Python, PHP, Java, and .NET app >> Try New Relic at no cost today and get our sweet Data Nerd shirt too! >> http://p.sf.net/sfu/newrelic-dev2dev >> _______________________________________________ >> Ipmitool-devel mailing list >> Ipmitool-devel@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/ipmitool-devel ------------------------------------------------------------------------------ Everyone hates slow websites. So do we. Make your web apps faster with AppDynamics Download AppDynamics Lite for free today: http://p.sf.net/sfu/appdyn_sfd2d_oct _______________________________________________ Ipmitool-devel mailing list Ipmitool-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ipmitool-devel