use proper variable name INSTANCE_NAME
[ext/instance-debootstrap.git] / common.sh
1
2 get_api5_arguments() {
3   TEMP=`getopt -o o:n:i:b:s: -n '$0' -- "$@"`
4   if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
5   # Note the quotes around `$TEMP': they are essential!
6   eval set -- "$TEMP"
7   while true; do
8     case "$1" in
9       -i|-n) instance=$2; shift 2;;
10
11       -o) old_name=$2; shift 2;;
12
13       -b) blockdev=$2; shift 2;;
14
15       -s) swapdev=$2; shift 2;;
16
17       --) shift; break;;
18
19       *)  echo "Internal error!"; exit 1;;
20     esac
21   done
22   if [ -z "$instance" -o -z "$blockdev" ]; then
23     echo "Missing OS API Argument"
24     exit 1
25   fi
26   if [ "$0" != "export" -a -z "$swapdev"  ]; then
27     echo "Missing OS API Argument"
28     exit 1
29   fi
30   if [ "$0" = "rename" -a -z "$new_name"  ]; then
31     echo "Missing OS API Argument"
32     exit 1
33   fi
34 }
35
36 get_api10_arguments() {
37   if [ -z "$INSTANCE_NAME" -o -z "$HYPERVISOR" -o -z "$DISK_COUNT" ]; then
38     echo "Missing OS API Variable"
39     exit 1
40   fi
41   instance=$INSTANCE_NAME
42   if [ $DISK_COUNT -lt 1 -o -z "$DISK_0_PATH" ]; then
43     echo "At least one disk is needed"
44     exit 1
45   fi
46   blockdev=$DISK_0_PATH
47   if [ "$0" = "rename" -a -z "$OLD_INSTANCE_NAME" ]; then
48     echo "Missing OS API Variable"
49   fi
50   old_name=$OLD_INSTANCE_NAME
51 }
52
53 if [ -z "$OS_API_VERSION" -o "$OS_API_VERSION" = "5" ]; then
54   OS_API_VERSION=5
55   get_api5_arguments
56 elif [ "$OS_API_VERSION" = "10" ]; then
57   get_api10_arguments
58   if [ $0 = "import" -o $0 = "export" ]; then
59     echo "import/export still not compatible with API version 10"
60     exit 1
61   fi
62 else
63   echo "Unknown OS API VERSION $OS_API_VERSION"
64   exit 1
65 fi