Инструменты пользователя

Инструменты сайта


Боковая панель

Связь

script_to_start_and_stop_vm_guests_on_vmware_server_2.0

Script to start and stop vm guests on vmware server

Homepage: Script to start and stop vm guests on vmware server 2.0

#!/bin/bash 
# This script will start/stop/status VMware machine
#
# Written by Ez-Aton
# http://www.tournament.org.il/run
#
# Modified for VMware server 2.0 by doka@wepoca.net
# http://www.wepoca.net
#
#
# Hardcoded. Change to match your own settings!
# the VMware storage name
VMSTORAGE="[standard]"

# the VM guest to be started/stopped
VMGUEST="YOUR_GUEST_VM/YOUR_GUEST_VM.vmx"

# the URL of the VMware host
HOST="https://URL_OF_VMWARE_HOST:8333/sdk"

# admin user on VMware host
HOST_USER="YOUR_ADMIN"
HOST_PWD="ADMIN_PWD"

# the VMware script 
VMRUN="/usr/bin/vmrun"
TIMEOUT=60

function status () { 

# This function will return success if the VM is up
$VMRUN -T server -h $HOST -u $HOST_USER -p $HOST_PWD list | grep "$VMGUEST" &>/dev/null

if [[ "$?" -eq "0" ]]

then

echo "VM $VMGUEST is up"

return 0

else

echo "VM $VMGUEST is down"

return 1

fi

}

function start () {

# This function will start the VM

$VMRUN -T server -h $HOST -u $HOST_USER -p $HOST_PWD start "$VMSTORAGE $VMGUEST"

if [[ "$?" -eq "0" ]]

then

echo "VM $VMGUEST is starting"

return 0

else

echo "$VMGUEST VM failed"

return 1

fi

}

function stop () {

# This function will stop the VM

$VMRUN -T server -h $HOST -u $HOST_USER -p $HOST_PWD suspend "$VMSTORAGE $VMGUEST"

for i in `seq 1 $TIMEOUT` do 

if status then 

echo

else

echo "VM $VMGUEST Stopped"

return 0

fi

sleep 1 done

# $VMRUN stop "$VMGUEST" soft

$VMRUN -T server -h $HOST -u $HOST_USER -p $HOST_PWD stop "$VMSTORAGE $VMGUEST" soft

}

case "$1" in

start) start

;;

stop) stop

;;

status) status

;; esac

RET=$?

exit $RET 



script_to_start_and_stop_vm_guests_on_vmware_server_2.0.txt · Последние изменения: 2011/02/22 11:07 (внешнее изменение)