#!/bin/sh
# This command is developed for VMware guest. 

######################################################################
# (C) Copyright 2008-2016 Hewlett Packard Enterprise Development, L.P.
# @(#) Product Name                :  HP Serviceguard
# @(#) Product Version             :  A.12.10.00
# @(#) Patch Name                  :  
#
# *** Note: This file MUST NOT be edited. *****
#
# Any changes made to it will be overwritten when you upgrade to the
# next release of HP Serviceguard.
#
# Changing this file may lead to unrecoverable Cluster failure.
#
######################################################################

 typeset -i maxtimeout
 typeset  option
 typeset  host
 typeset  arch
 typeset  cmd

 maxtimeout=0
 option=$1

 # Only vminfo -M is supported.
 # cmvminfo is symbolic link and pointing to vminfo.

 if  [ $# -lt 1 ];then
     echo "Wrong usage, only "vminfo -M" is supported."
     exit -1
 fi

 if [ $option == "-h" ] || [ $option == "-H" ] || [ $option == "--help" ] || [ $option == "--HELP" ];then
     echo " vminfo for Serviceguard on Linux displays only three fields."
     echo " It always displays 'guest' in first field as it has been developed "
     echo " for VMware ESX guests only."
     echo ' It displays the ESX host name (on which the guest is residing ) in 6th field.'
     echo " It displays HBA driver timeout value '0' in 12th field. "
     exit -1
 fi

 if [ $# -ne 1 ] || [ $option != "-M" ];then
  echo "Wrong usage, only "vminfo -M" is supported."
  logger "Wrong usage, only 'vminfo -M' is supported."
  exit -1
 fi
 arch=`arch`
 if [ $arch == "ia64" ];then
     echo "vminfo command is not supported on IA64 machine "
     exit -1
 fi

 # This command should be used on VMware guest only.
 # check whether VMware tools is installed and running on the guest.

 if [ -x /usr/sbin/vmware-guestd ];then
     cmd="/usr/sbin/vmware-guestd"
 fi

 if [ -x /usr/sbin/vmtoolsd ];then
     cmd="/usr/sbin/vmtoolsd"
 fi

 # On RH7, SLES11 SP4, SLES12 and their later releases VMware tools are
 # available as part of OS bundle. When they are installed as rpm the 
 # location of vmtoolsd is changed.

 if [ -x /usr/bin/vmtoolsd ];then
     cmd="/usr/bin/vmtoolsd"
 fi

 if [[ -n $cmd ]];then
     # Getting hostname
     host=`$cmd  --cmd "info-get guestinfo.machine.id" 2> /dev/null`
     if [[ -z $host ]]; then
         logger " Warning : Could not get hostname"
         logger " May be machine.id is not set in guest .vmx file on ESX host"
         logger " Or VMware tools are not configured properly"
         host="No value found"
     fi
 else
     echo " Error : Unable to execute vmware-guestd or vmtoolsd command "
     echo " This command can be executed only on VMware guest"
     echo " If you are trying to execute this command on VMware guest "
     echo " Please check either VMware tools is not installed on this system "
     echo " Or it does not have execute permission."

     logger " Error : Unable to execute vmware-guestd or vmtoolsd command "
     logger " This command can be executed only on VMware guest"
     logger " If you are trying to execute this command on VMware guest "
     logger " Please check either VMware tools is not installed on this system "
     logger " Or it does not have execute permission."
     exit -1
 fi

 # displaying system type(will be guest always),  Host name and time out value.
 echo ":guest:0:0:0:0:$host:0:0:0:0:0:$maxtimeout:"
