Files
xen/tools/examples/external-device-migrate
T
kaf24@firebug.cl.cam.ac.uk 3f37f70c65 Clean up and refactor some parts of the vTPM and migration-related scripts.
In the external device migration script I am introducing a subtype
(-subtype <subtype>) from which the script's name is formed. Also all
unparsed parameters are passed to the called script.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
2006-05-10 16:01:34 +01:00

112 lines
2.9 KiB
Bash

#!/bin/sh
# Copyright (c) 2005 IBM Corporation
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of version 2.1 of the GNU Lesser General Public
# License as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# This script is called by XenD for migration of external devices
# It does not handle the migration of those devices itself, but
# passes the requests on to further applications
# It handles the low-level command line parsing and some of the
# synchronization
dir=$(dirname "$0")
. "$dir/logging.sh"
function ext_dev_migrate_usage() {
cat <<EOF
Pass the following command line parameters to the script:
-step <n> : n-th migration step
-host <host> : the destination host
-domname <domain name> : name of the domain that is migrating
-type <device type> : the type of device that is migrating
-subtype <dev. subtype>: the subtype of the device
-recover : indicates recovery request; an error
occurred during migration
-help : display this help screen
EOF
}
# Parse the command line paramters. The following parameters must be
# passed as the first ones in the sequence:
# -step [required]
# -host [required]
# -domname [required]
# -type [required]
# -subtype [optional]
# -recover [optional]
# The remaining ones will be passed to the called function.
function evaluate_params()
{
local step host domname typ recover filename func stype
stype=""
while [ 1 ]; do
if [ "$1" == "-step" ]; then
shift
step=$1
elif [ "$1" == "-host" ]; then
shift
host=$1
elif [ "$1" == "-domname" ]; then
shift
domname=$1
elif [ "$1" == "-type" ]; then
shift
typ=$1
elif [ "$1" == "-subtype" ]; then
shift
stype="_$1"
elif [ "$1" == "-recover" ]; then
recover=1
elif [ "$1" == "-help" ]; then
ext_dev_migrate_usage
exit
else
break
fi
shift
done
if [ "$step" == "" -o \
"$host" == "" -o \
"$typ" == "" -o \
"$domname" == "" ]; then
echo "Error: Parameter(s) missing (-step/-host/-type/-domname)"
echo ""
echo "$0 -help for usage."
exit
fi
filename="$dir/$typ$stype-migration.sh"
if [ ! -r $filename ]; then
echo "Error: Could not find script '$filename'"
return
fi
. "$filename"
if [ "$recover" == "1" ]; then
func="$typ"_recover
eval $func $host $domname $step $*
else
func="$typ"_migration_step
eval $func $host $domname $step $*
fi
}
evaluate_params $*