On 2010-03-01 11:34, Cristian Mammoli - Apra Sistemi wrote: > Florian Haas wrote: > >>> How can I get an up to date version of your RA? >> >> Here: >> http://hg.linux-ha.org/agents/raw-file/tip/heartbeat/vmware >> > > > I made some additional modification and created a patch file against > this script. I moved the "set_env" function inside the "validate-all" > function.
OK, your patch introduced a few whitespace errors and made a few other whitespace-only changes. I've tried to remove those. A new hg export (hopefully with functional changes only) is attached, I'll comment on that in a moment. Cheers, Florian
# HG changeset patch # User Cristian Mammoli <[email protected]> # Date 1267442397 -3600 # Branch mysql-ms # Node ID bdf0e4616c7329aa3d2031e28d2cbaf1fd94ab7d # Parent 435f3775df694592d1233eeddfb55ea6ae76199e Medium: RA: new version of vmware RA Several changes to the vmware RA: * Rename set_environment() to vmware_set_env() * Change suggested timeouts to 900s * Exit on validation error, don't return * Make vmware_stop more reliable * Invoke validate before any action except usage and meta-data * Add more comments and update RA version diff -r 435f3775df69 -r bdf0e4616c73 heartbeat/vmware --- a/heartbeat/vmware Fri Feb 26 14:06:46 2010 +0100 +++ b/heartbeat/vmware Mon Mar 01 12:19:57 2010 +0100 @@ -2,16 +2,16 @@ # # VMware OCF resource agent # -# Copyright (c) 2008 Apra Sistemi s.r.l. +# Copyright (c) 2010 Apra Sistemi s.r.l. # All Rights Reserved. # -# Description: Manages a VMware server 2.0 as a High-Availability -# resource +# Description: Manages VMware server 2.0 virtual machines +# as High-Availability resources # # # Author: Cristian Mammoli <c.mammoli AT apra DOT it> # License: GNU General Public License (GPL) -# Copyright: (C) 2008 Apra Sistemi s.r.l. +# Copyright: (C) 2010 Apra Sistemi s.r.l. # # See usage() function below for more details... # @@ -20,12 +20,16 @@ # * 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 +# * vmware-server 2.0 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 +# dealing with many virtual machines: raise it to something around 900 secs # or use operation attributes with the proposed values +# * Moving a vm among nodes will cause its mac address to change: if you need +# to preserve the mac address set it manually in the nic options +# * The script should be able to deal with paths and filenames with spaces, +# anyway try to avoid it # Initialization ################################################################# @@ -43,7 +47,7 @@ # Path to the vmware-vim-cmd executable VIMSHBIN="$OCF_RESKEY_vimshbin" -# global variables +# Global variables VMXDIR= RELVMXPATH= VMID= @@ -68,33 +72,33 @@ # Get message id vmware_get_msgid() { $VIMSHBIN vmsvc/message $1 2>/dev/null \ - | awk '/^Virtual machine message/ {print $4}' \ - | awk -F : '{print $1}' + | awk '/^Virtual machine message/ {print $4}' \ + | awk -F : '{print $1}' } # Answers message vmware_answer_msg() { - $VIMSHBIN vmsvc/message $1 $2 $3 >/dev/null 2>&1 + $VIMSHBIN vmsvc/message $1 $2 $3 &> /dev/null } # Register a virtual machine vmware_register_vm() { - $VIMSHBIN solo/registervm '"'$1'"' >/dev/null 2>&1 + $VIMSHBIN solo/registervm '"'$1'"' &> /dev/null } # Unregister a virtual machine vmware_unregister_vm() { - $VIMSHBIN vmsvc/unregister $1 >/dev/null 2>&1 + $VIMSHBIN vmsvc/unregister $1 &> /dev/null } # Start a virtual machine vmware_poweron_vm() { - $VIMSHBIN vmsvc/power.on $1 >/dev/null 2>&1 + $VIMSHBIN vmsvc/power.on $1 &> /dev/null } # Suspend a virtual machine vmware_suspend_vm() { - $VIMSHBIN vmsvc/power.suspend $1 >/dev/null 2>&1 + $VIMSHBIN vmsvc/power.suspend $1 &> /dev/null } # Get virtual machine power state @@ -106,13 +110,13 @@ # Get vid of missing virtual machines vmware_get_broken() { $VIMSHBIN vmsvc/getallvm 2>&1 \ - | awk -F "'" '/^Skipping/ {print $2}' + | awk -F \' '/^Skipping/ {print $2}' } # Variables depending on the above functions ################################################################# -set_environment() { +vmware_set_env() { # Directory containing the virtual machine VMXDIR="`dirname "$VMXPATH"`" @@ -126,7 +130,7 @@ VM="`awk -F '"' '/^displayName/ {print $2}' "$VMXPATH"`" # msg.autoAnswer value in config file - VMAUTOMSG="`awk -F '"' '/^msg.autoAnswer/ {print $2}' "$VMXPATH"`" + VMAUTOMSG="`awk -F '"' '/^msg.autoAnswer/ {print toupper($2)}' "$VMXPATH"`" } # Main functions @@ -141,27 +145,30 @@ END } -# Check for dependencies # Check for mandatory files presence and consistency vmware_validate() { if [ -z "`pidof vmware-hostd`" ]; then - ocf_log warn "vmware-hostd is not running" - return $OCF_ERR_GENERIC + ocf_log err "vmware-hostd is not running: aborting" + exit $OCF_ERR_GENERIC fi if [ ! -x "$VIMSHBIN" ]; then - ocf_log warn "vmware-vimsh executable missing or not in path ($VIMSHBIN)" - return $OCF_ERR_INSTALLED + ocf_log err "vmware-vim-cmd executable missing or not in path ($VIMSHBIN): aborting" + exit $OCF_ERR_ARGS fi if [ ! -f "$VMXPATH" ]; then - ocf_log warn "Specified vmx file ($VMXPATH) does not exist" - return $OCF_ERR_ARGS + ocf_log err "Specified vmx file ($VMXPATH) does not exist: aborting" + exit $OCF_ERR_ARGS fi + # Now we can safely setup variables... + vmware_set_env + + # ... and verify them if [ -z "$VM" ]; then - ocf_log warn "Could not find out virtual machine name" - return $OCF_ERR_ARGS + ocf_log err "Could not find out virtual machine name: aborting" + exit $OCF_ERR_ARGS fi if [ "$VMAUTOMSG" != "TRUE" ]; then @@ -221,7 +228,7 @@ # Check if the VM is running. We don't bother # with timeouts: we rely on the CRM for that. while :; do - vmware_monitor && break + vmware_monitor && break ocf_log info "Virtual machine $VM is still stopped: delaying 10 seconds" sleep 10 done @@ -253,12 +260,20 @@ else ocf_log info "Virtual machine $VM is already stopped" fi + # VMware randomly fails to unregister VMs, + # so we send the command twice ocf_log info "Unregistering virtual machine $VM" vmware_unregister_vm $VMID VMID=`vmware_get_vid "$RELVMXPATH"` if [ -n "$VMID" ]; then - ocf_log err "Could not unregister virtual machine $VM: aborting." - exit $OCF_ERR_GENERIC + ocf_log warn "Could not unregister virtual machine $VM: retrying." + sleep 10 + vmware_unregister_vm $VMID + VMID=`vmware_get_vid "$RELVMXPATH"` + if [ -n "$VMID" ]; then + ocf_log err "Could not unregister virtual machine $VM: aborting." + exit $OCF_ERR_GENERIC + fi fi ocf_log info "Virtual machine $VM is stopped" return $OCF_SUCCESS @@ -278,11 +293,11 @@ # Print metadata informations meta_data() { - cat <<END + cat <<END <?xml version="1.0"?> <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd"> -<resource-agent name="vmware"> -<version>0.1</version> +<resource-agent name="VMwareVM"> +<version>0.2</version> <longdesc lang="en"> OCF compliant script to control vmware server 2.0 virtual machines. </longdesc> @@ -301,15 +316,15 @@ <longdesc lang="en"> vmware-vim-cmd executable path </longdesc> -<shortdesc lang="en">vmware-vimsh path</shortdesc> +<shortdesc lang="en">vmware-vim-cmd path</shortdesc> <content type="string" default="/usr/bin/vmware-vim-cmd"/> </parameter> </parameters> <actions> -<action name="start" timeout="300" /> -<action name="stop" timeout="300" /> -<action name="monitor" timeout="30" interval="300" depth="0" /> +<action name="start" timeout="900" /> +<action name="stop" timeout="900" /> +<action name="monitor" timeout="30" interval="300" depth="0" start-delay="60" /> <action name="meta-data" timeout="5" /> </actions> </resource-agent> @@ -319,46 +334,34 @@ # See how we were called ################################################################# -case "$1" in +case $1 in meta-data) meta_data exit $OCF_SUCCESS ;; + +start) + vmware_validate + vmware_start + ;; + +stop) + vmware_validate + vmware_stop + ;; + +status|monitor) + vmware_validate + vmware_monitor + ;; + usage|help) vmware_usage exit $OCF_SUCCESS ;; -esac -set_environment -vmware_validate -rc=$? -if [ $rc -ne 0 ]; then - case "$1" in - stop) ocf_log info "validate failed, vmware considered stopped" - exit $OCF_SUCCESS;; - monitor) exit $OCF_NOT_RUNNING;; - status) exit $LSB_STATUS_STOPPED;; - *) # it's safe to bail out now - ocf_log err "vmware_validate failed" - exit $rc - ;; - esac -elif [ "$1" = "validate-all" ]; then - exit $OCF_SUCCESS -fi - -case "$1" in -start) - vmware_start - ;; - -stop) - vmware_stop - ;; - -status|monitor) - vmware_monitor +validate-all) + vmware_validate ;; *) @@ -367,3 +370,5 @@ ;; esac + +exit $?
signature.asc
Description: OpenPGP digital signature
_______________________________________________________ Linux-HA-Dev: [email protected] http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev Home Page: http://linux-ha.org/
