From 65ecb979d4679e45eacae713405e028b714e50ea Mon Sep 17 00:00:00 2001
From: Jaime Melis <jmelis@opennebula.org>
Date: Tue, 24 Apr 2012 15:44:58 +0200
Subject: [PATCH] Feature #1222: Fix context scripts with variable number of
 arguments.

---
 src/tm_mad/common/context | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/tm_mad/common/context b/src/tm_mad/common/context
index a37c4b7f07..913789c62e 100755
--- a/src/tm_mad/common/context
+++ b/src/tm_mad/common/context
@@ -23,13 +23,19 @@
 #   - vmid is the id of the VM
 #   - 0 is the target datastore (system)
 
-while (( "$#" )); do
-    if [ "$#" == "1" ]; then
-        DST=$1
+i=1
+for arg in "$@"; do
+    if [ $i -eq $# ]; then
+        DS_ID="$arg"
+    elif [ $i -eq $(($#-1)) ]; then
+        VM_ID="$arg"
+    elif [ $i -eq $(($#-2)) ]; then
+        DST="$arg"
     else
-        SRC="$SRC $1"
+        SRC="$SRC $arg"
     fi
-    shift
+
+    let i=i+1
 done
 
 if [ -z "${ONE_LOCATION}" ]; then