I am using Netapp Flexclone and want to register my VM's with a script.
Have a look at http://www.youtube.com/watch?v=7Miv0PiJFzM
I got this script from Netapp , but have no idea ?
Have anybody tried this before ? and if so , how ?
Thanks
#!/usr/bin/bash
#
Example code to register and start all VMs
#
This sample code is provided AS IS, with no support or warranties of any
kind, including but not limited to warranties of merchantability or
or fitness of any kind, expressed or implied.
#
Network Appliance
#
--------------------------------------------------------------------------
VERBOSE=0
LOGFILE=/dev/null
RSH=/usr/bin/ssh
RSH_USER=root
RSH_CMD="$ -l $
"
#
#
write2log()
{
TEXT=$1
echo "`date '+%D %T'` \c" >> ${LOGFILE} 2>&1
echo ": $" >> $ 2>&1
if ; then
echo $1
else
RES=`echo $ | egrep '(WARNING|ERROR)'`
if [ "$" ] ; then
echo $1
fi
fi
}
#
#
check_server()
{
SERVER=$1
write2log "check_server(): Checking network access to server ${SERVER} ..."
result=`/usr/bin/ping $ -n 3 > /dev/null 2>&1`
if ; then
write2log "check_server(): ERROR: $ is not available on the network"
exit 1
else
write2log "check_server(): Server $
is on the network."
fi
write2log "check_server(): Checking remote access to server $ ..."
result=`$ $ "id"`
tr=`echo "$result" | grep $`
if [ "$" = "" ] ; then
write2log "check_server(): ERROR: $ is not accessible with ($)!" exit 1 fi write2log "check_server(): access with ($) to $ successful."
}
#
Name: run_vmhost
Func: Run the operations for each VMWare host specified on the command line.
#
run_vmhost()
{
assign the server
SERVER=$1
write2log "run_vmhost(): Starting VMs on server ${SERVER} ..."
first make sure the host specified is up
check_server $
write2log "run_vmhost(): Running $ $ find /vmfs/volumes -mindepth 3 -maxdepth 3 -name '*.vmx' -print ..."
VMXES=`$ $ "find /vmfs/volumes -mindepth 3 -maxdepth 3 -name '*.vmx' -print"` if ; then write2log "run_vmhost(): ERROR: Execution of $ failed!"
exit 1
fi
if [ "$
" != "" ] ; then
for VMX in $ ; do
register the VM
write2log "run_vmhost(): Running $ $ /usr/bin/vmware-cmd -s register $ ..."
$ $ "/usr/bin/vmware-cmd -s register $"
if ; then
write2log "run_vmhost(): ERROR: Execution of $
failed!"
exit 1
fi
write2log "run_vmhost(): Running $ $ /usr/bin/vmware-cmd $ start ..."
18
$ $ "/usr/bin/vmware-cmd $ start"
write2log "run_vmhost(): ERROR: Execution of $ failed!"
exit 1
else
write2log "run_vmhost(): VM $ started."
fi
done
else
write2log "run_vmhost(): WARNING: Server $ did not have any VMFS volumes active!" fi write2log "run_vmhost(): Configuration of server $ completed."
}
#
MAIN SCRIPT
#
ARGS=$#
case "$1" in
-v) VERBOSE=1 ; ARGS=`expr $ - 1` ; shift ;; *) HOST=$1 ; shift ; ARGS=`expr $ - 1` ; run_vmhost $HOST ;;
esac
done
write2log "Script completed."
The script does a lot of tasks to include checking hosts, finding vmfs volumes, and registering and starting vm's.
If all you want to do is register vm's, then you can use 'vmware-cmd -s register /path/to/vmx/file.vmx' on an esx host.
-KjB
Thanks , I know but I have 100 VM's in each datastore and the vmware-cmd register only does one at a time.
Can I use a variable in the $whatever.vmx to register everything in the datastore ?
Tx
Yes, do this for a quick and dirty method below. For any outliers, you'll have to go back and add manually.
Log into your service console.
Cd to your /vmfs/volumes folder
cd
repeat steps
-KjB
Message was edited by: kjb007 : fixed loop
Sorry, those are backticks, not single quotes, the one next to the 1 on your keyboard. Otherwise, just change the `pwd`/$vm/$vm.vmx to /vmfs/volume/datastore_name/$vm/$vm.vmx
-KjB
This looks very helpful.
What if you have VMs with multiple disks, and some of those disks are located on other datastores? Will it still register properly?
Thanks
-N