The problem I was seeing was that $OCF_RESKEY_vmxpath was not being set,
and even if it were, it could only start or stop a single virtual
machine. Rather than making the script try to parse multiple arguments
and loop through a list of machines, I decided to just put a "shim"
script in there to call the agent for each VM.
Dejan Muhamedagic wrote:
> Hi,
>
> On Thu, Dec 18, 2008 at 11:48:46AM -0500, Jason Noble wrote:
>
>> I had a customer who tried to use this script, but it didn't work. I
>> made some modifications to the control script. Additionally, the
>> customer wanted to start/stop multiple machines. The solution
>> implemented makes the Resource Agent a simple script -- vmstart_all --
>> that makes multiple calls to vmstart in order to start/stop the virtual
>> machines.
>>
>
> Thanks for sharing the RA. BTW, what's wrong with having multiple
> VM resources?
>
> Thanks,
>
> Dejan
>
>
>> Here is vmstart_all:
>>
>> #!/bin/bash
>> VMSTARTDIR="/etc/ha.d/resource.d"
>> # Start up multiple virtual machines
>> # enter one per line in the following format:
>> # $VMSTARTDIR/vmstart $1 directoryname
>> #
>> # where directoryname is the name of the
>> # directory that contains a .vmx file
>> $VMSTARTDIR/vmstart $1 vm1
>> $VMSTARTDIR/vmstart $1 vm2
>>
>> And here's the patch for vmstart:
>> --- vmstart.20081114 2008-12-18 11:02:30.000000000 -0500
>> +++ vmstart 2008-12-18 11:12:45.000000000 -0500
>> @@ -31,79 +31,106 @@
>> #################################################################
>>
>> # Source ocf shell functions
>> -#. ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs
>> -. /usr/lib64/heartbeat/ocf-shellfuncs
>> -#. /etc/ha.d/shellfuncs
>> +OCF_ROOT=/usr/lib/ocf
>> +. ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs
>> +#. /usr/lib64/heartbeat/ocf-shellfuncs
>> +. /etc/ha.d/shellfuncs
>> +
>> # Basic variables configuration
>> #################################################################
>>
>> # Path to the virtual machine configuration file
>> -VMXPATH="$OCF_RESKEY_vmxpath"
>> +#VMXPATH="$OCF_RESKEY_vmxpath"
>> +VMXPATH="/mnt/vmware/$2"
>>
>> # Path to the vmware-vim-cmd executable
>> -VIMSHBIN="$OCF_RESKEY_vimshbin"
>> +#VIMSHBIN="$OCF_RESKEY_vimshbin"
>> +VIMSHBIN="/usr/bin/vmware-vim-cmd"
>> +
>> +# Additional options to pass to vmware-vim-cmd executable
>> +VIMSHBINOPTS="-H localhost -O 904"
>> +
>> +# Print usage summary
>> +vmware_usage() {
>> +cat <<EOF
>> +usage: $0 VMDIR {start|stop|status|monitor|meta-data|validate-all}
>> +
>> +VMDIR A directory under $VMXPATH that contains a virtual machine.
>> +EOF
>> +}
>> +
>> +# Check for two parameters
>> +if [ "$2" == "" ]; then
>> + vmware_usage
>> + exit 0
>> +fi
>> +
>>
>> # vmware-vim-cmd functions
>> #################################################################
>>
>> # Get virtual machine vid
>> vmware_get_vid() {
>> -$VIMSHBIN vmsvc/getallvms 2>/dev/null | awk '/\/'"$1"'/ {print $1}'
>> +$VIMSHBIN $VIMSHBINOPTS 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/
>> +$VIMSHBIN $VIMSHBINOPTS 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}'
>> +$VIMSHBIN $VIMSHBINOPTS 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 $VIMSHBINOPTS vmsvc/message $1 $3 $4 &> /dev/null
>> }
>>
>> # Register a virtual machine
>> vmware_register_vm() {
>> -$VIMSHBIN solo/registervm '"'$1'"' &> /dev/null
>> +$VIMSHBIN $VIMSHBINOPTS solo/registervm '"'$1'"' &> /dev/null
>> }
>>
>> # Unregister a virtual machine
>> vmware_unregister_vm() {
>> -$VIMSHBIN vmsvc/unregister $1 &> /dev/null
>> +$VIMSHBIN $VIMSHBINOPTS vmsvc/unregister $1 &> /dev/null
>> }
>>
>> # Start a virtual machine
>> vmware_poweron_vm() {
>> -$VIMSHBIN vmsvc/power.on $1 &> /dev/null
>> +$VIMSHBIN $VIMSHBINOPTS vmsvc/power.on $1 &> /dev/null
>> }
>>
>> # Suspend a virtual machine
>> vmware_suspend_vm() {
>> -$VIMSHBIN vmsvc/power.suspend $1 &> /dev/null
>> +$VIMSHBIN $VIMSHBINOPTS vmsvc/power.suspend $1 &> /dev/null
>> }
>>
>> # Get virtual machine power state
>> vmware_get_status() {
>> -$VIMSHBIN vmsvc/power.getstate $1 2>/dev/null | awk '/^Powered on/ ||
>> /^Powered off/ || /^Suspended/'
>> +$VIMSHBIN $VIMSHBINOPTS 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}'
>> +$VIMSHBIN $VIMSHBINOPTS vmsvc/getallvm 2>&1 | awk -F "'" '/^Skipping/
>> {print $2}'
>> }
>>
>> # Variables depending on the above functions
>> #################################################################
>>
>> # Directory containing the virtual machine
>> -VMXDIR="`dirname "$VMXPATH"`"
>> +#VMXDIR="`dirname "$VMXPATH"`"
>> +VMXDIR=$VMXPATH
>>
>> # Basename of the configuration file
>> -RELVMXPATH="`basename "$VMXPATH"`"
>> +#RELVMXPATH="`basename "$VMXPATH"`"
>> +RELVMXPATH=`basename "$(ls -1 $VMXPATH/*.vmx 2>/dev/null| head -n1)"
>> 2>/dev/null`
>> +
>> +VMXPATH=$VMXDIR/$RELVMXPATH
>>
>> # Vid of the virtual machine (can be empty if the vm is not registered)
>> VMID=`vmware_get_vid "$RELVMXPATH"`
>> @@ -120,15 +147,6 @@
>> # Main functions
>> #################################################################
>>
>> -# Print usage summary
>> -vmware_usage() {
>> -cat <<END
>> -usage: $0 {start|stop|status|monitor|meta-data|validate-all}
>> -
>> -Expects to have a fully populated OCF RA-compliant environment set.
>> -END
>> -}
>> -
>> # Check for mandatory files presence and consistency
>> vmware_validate() {
>> if [ -z "`pidof vmware-hostd`" ]; then
>> @@ -182,7 +200,7 @@
>> if [ -z "$VMID" ]; then
>> # VM is not registered, need to register
>> ocf_log info "Virtual machine $VM is not registered"
>> -ocf_log info "Registering Virtual machine $VM"
>> +ocf_log info "Registering Virtual machine $VM >>>> $VMXPATH"
>> vmware_register_vm "$VMXPATH"
>> VMID=`vmware_get_vid "$RELVMXPATH"`
>> if [ -z "$VMID" ]; then
>> @@ -269,7 +287,7 @@
>>
>> # Print metadata informations
>> meta_data() {
>> -cat <<END
>> +cat <<EOF
>> <?xml version="1.0"?>
>> <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
>> <resource-agent name="vmwarevm">
>> @@ -305,7 +323,7 @@
>> <action name="meta-data" timeout="5" />
>> </actions>
>> </resource-agent>
>> -END
>> +EOF
>> }
>>
>> # See how we were called
>> _______________________________________________
>> Linux-HA mailing list
>> [email protected]
>> http://lists.linux-ha.org/mailman/listinfo/linux-ha
>> See also: http://linux-ha.org/ReportingProblems
>>
> _______________________________________________
> Linux-HA mailing list
> [email protected]
> http://lists.linux-ha.org/mailman/listinfo/linux-ha
> See also: http://linux-ha.org/ReportingProblems
>
_______________________________________________
Linux-HA mailing list
[email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems