diff --git a/heartbeat/vmware b/heartbeat/vmware index bc1a83196..52c22b567 100644 --- a/heartbeat/vmware +++ b/heartbeat/vmware @@ -1,350 +1,350 @@ #!/bin/sh # # VMware OCF resource agent # # Copyright (c) 2008 Apra Sistemi s.r.l. # All Rights Reserved. # # Description: Manages a VMware server 2.0 as a High-Availability # resource # # # Author: Cristian Mammoli # License: GNU General Public License (GPL) # Copyright: (C) 2008 Apra Sistemi s.r.l. # # See usage() function below for more details... # # OCF instance parameters: # * OCF_RESKEY_VMXPATH (mandatory, full path to the virtual machine vmx file) # * OCF_RESKEY_VIMSHBIN (mandatory, full path to th vmware-vim-cmd executable) # # Requirements/caveats: # * vmware-server 2.0 RC1 installed and autostarted on all nodes # * vmdk files must be in the same directory of the vmx file # * vmx filenames must be unique, even if stored in different directories # * Default_Action_Timeout stock value (20 sec) isn't enough if you are # dealing with many virtual machines: raise it to something around 300 secs # or use operation attributes with the proposed values # Initialization ################################################################# # Source ocf shell functions . ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs # Basic variables configuration ################################################################# # Path to the virtual machine configuration file VMXPATH="$OCF_RESKEY_vmxpath" # Path to the vmware-vim-cmd executable VIMSHBIN="$OCF_RESKEY_vimshbin" # vmware-vim-cmd functions ################################################################# # Get virtual machine vid vmware_get_vid() { $VIMSHBIN vmsvc/getallvms 2>/dev/null \ | awk '/\/'"$1"'/ {print $1}' } # Is the vm waiting for input after a migration? vmware_uuid_alt() { $VIMSHBIN vmsvc/message $1 2>/dev/null \ | awk /^msg.uuid.altered/ } # Get message id vmware_get_msgid() { $VIMSHBIN vmsvc/message $1 2>/dev/null \ | awk '/^Virtual machine message/ {print $4}' \ | awk -F : '{print $1}' } # Answers message vmware_answer_msg() { - $VIMSHBIN vmsvc/message $1 $2 $3 &> /dev/null + $VIMSHBIN vmsvc/message $1 $2 $3 >/dev/null 2>&1 } # Register a virtual machine vmware_register_vm() { - $VIMSHBIN solo/registervm '"'$1'"' &> /dev/null + $VIMSHBIN solo/registervm '"'$1'"' >/dev/null 2>&1 } # Unregister a virtual machine vmware_unregister_vm() { - $VIMSHBIN vmsvc/unregister $1 &> /dev/null + $VIMSHBIN vmsvc/unregister $1 >/dev/null 2>&1 } # Start a virtual machine vmware_poweron_vm() { - $VIMSHBIN vmsvc/power.on $1 &> /dev/null + $VIMSHBIN vmsvc/power.on $1 >/dev/null 2>&1 } # Suspend a virtual machine vmware_suspend_vm() { - $VIMSHBIN vmsvc/power.suspend $1 &> /dev/null + $VIMSHBIN vmsvc/power.suspend $1 >/dev/null 2>&1 } # Get virtual machine power state vmware_get_status() { $VIMSHBIN vmsvc/power.getstate $1 2>/dev/null \ | awk '/^Powered on/ || /^Powered off/ || /^Suspended/' } # Get vid of missing virtual machines vmware_get_broken() { $VIMSHBIN vmsvc/getallvm 2>&1 \ | awk -F "'" '/^Skipping/ {print $2}' } # Variables depending on the above functions ################################################################# # Directory containing the virtual machine VMXDIR="`dirname "$VMXPATH"`" # Basename of the configuration file RELVMXPATH="`basename "$VMXPATH"`" # Vid of the virtual machine (can be empty if the vm is not registered) VMID=`vmware_get_vid "$RELVMXPATH"` # Power state of the virtual machine (can be empty if the vm is not registered) VMSTATE="`vmware_get_status $VMID`" # Virtual machine name VM="`awk -F '"' '/^displayName/ {print $2}' "$VMXPATH"`" # msg.autoAnswer value in config file VMAUTOMSG="`awk -F '"' '/^msg.autoAnswer/ {print $2}' "$VMXPATH"`" # Main functions ################################################################# # Print usage summary vmware_usage() { cat < 0.1 OCF compliant script to control vmware server 2.0 virtual machines. VMWare server 2.0 resource agent VMX configuration file path VMX file path vmware-vim-cmd executable path vmware-vimsh path END } # See how we were called ################################################################# case $1 in meta-data) meta_data exit $OCF_SUCCESS ;; start) vmware_validate vmware_start ;; stop) vmware_stop ;; status|monitor) vmware_monitor ;; usage|help) vmware_usage exit $OCF_SUCCESS ;; validate-all) vmware_validate ;; *) vmware_usage exit $OCF_ERR_UNIMPLEMENTED ;; esac exit $?