diff --git a/src/datastore_mad/remotes/ceph/monitor b/src/datastore_mad/remotes/ceph/monitor index b4d22f6559..406cc1c4ab 100755 --- a/src/datastore_mad/remotes/ceph/monitor +++ b/src/datastore_mad/remotes/ceph/monitor @@ -51,7 +51,7 @@ done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \ BRIDGE_LIST="${XPATH_ELEMENTS[j++]}" POOL_NAME="${XPATH_ELEMENTS[j++]:-$POOL_NAME}" -HOST=`get_destination_host $IMAGE_ID` +HOST=`get_destination_host` if [ -z "$HOST" ]; then error_message "Datastore template missing 'BRIDGE_LIST' attribute." diff --git a/src/datastore_mad/remotes/iscsi/monitor b/src/datastore_mad/remotes/iscsi/monitor index 727e433948..45fc9c5b60 100755 --- a/src/datastore_mad/remotes/iscsi/monitor +++ b/src/datastore_mad/remotes/iscsi/monitor @@ -51,7 +51,7 @@ done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \ BRIDGE_LIST="${XPATH_ELEMENTS[j++]}" VG_NAME="${XPATH_ELEMENTS[j++]:-$VG_NAME}" -HOST=`get_destination_host $IMAGE_ID` +HOST=`get_destination_host` if [ -z "$HOST" ]; then error_message "Datastore template missing 'BRIDGE_LIST' attribute." diff --git a/src/datastore_mad/remotes/libfs.sh b/src/datastore_mad/remotes/libfs.sh index 5b35d2bfaf..6320b6c555 100644 --- a/src/datastore_mad/remotes/libfs.sh +++ b/src/datastore_mad/remotes/libfs.sh @@ -211,7 +211,14 @@ function check_restricted { # @return host to be used as bridge #------------------------------------------------------------------------------- function get_destination_host { - HOSTS_ARRAY=($BRIDGE_LIST) - ARRAY_INDEX=`expr $1 % ${#HOSTS_ARRAY[@]}` - echo ${HOSTS_ARRAY[$ARRAY_INDEX]} + HOSTS_ARRAY=($BRIDGE_LIST) + N_HOSTS=${#HOSTS_ARRAY[@]} + + if [ -n "$1" ]; then + ARRAY_INDEX=$(($1 % ${N_HOSTS})) + else + ARRAY_INDEX=$((RANDOM % ${N_HOSTS})) + fi + + echo ${HOSTS_ARRAY[$ARRAY_INDEX]} } diff --git a/src/datastore_mad/remotes/lvm/monitor b/src/datastore_mad/remotes/lvm/monitor index 03f21a87d4..f431e09690 100755 --- a/src/datastore_mad/remotes/lvm/monitor +++ b/src/datastore_mad/remotes/lvm/monitor @@ -51,7 +51,7 @@ done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \ BRIDGE_LIST="${XPATH_ELEMENTS[j++]}" VG_NAME="${XPATH_ELEMENTS[j++]:-$VG_NAME}" -HOST=`get_destination_host $IMAGE_ID` +HOST=`get_destination_host` if [ -z "$HOST" ]; then error_message "Datastore template missing 'BRIDGE_LIST' attribute." diff --git a/src/datastore_mad/remotes/vmfs/monitor b/src/datastore_mad/remotes/vmfs/monitor index 9b48554127..c335f3fadd 100755 --- a/src/datastore_mad/remotes/vmfs/monitor +++ b/src/datastore_mad/remotes/vmfs/monitor @@ -50,7 +50,12 @@ done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/BASE_PATH \ BASE_PATH="${XPATH_ELEMENTS[0]}" BRIDGE_LIST="${XPATH_ELEMENTS[1]}" -HOST=`get_destination_host $ID` +HOST=`get_destination_host` + +if [ -z "$HOST" ]; then + error_message "Datastore template missing 'BRIDGE_LIST' attribute." + exit -1 +fi # ------------ Compute datastore usage -------------