From 948f929f6a431b7be248ce185f4d8d04340b3f50 Mon Sep 17 00:00:00 2001 From: Jan Orel Date: Thu, 17 Jan 2019 17:47:19 +0100 Subject: [PATCH] B #1136 Filter out only hosts which are off, disabled or error * There still might be hosts which are part of Ceph cluster but not OpenNebula * The host might be added afterwards --- src/datastore_mad/remotes/libfs.sh | 36 ++++++++++++++++++------------ 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/datastore_mad/remotes/libfs.sh b/src/datastore_mad/remotes/libfs.sh index 8986bb9fdc..eb10478907 100644 --- a/src/datastore_mad/remotes/libfs.sh +++ b/src/datastore_mad/remotes/libfs.sh @@ -451,22 +451,24 @@ function check_restricted { } #------------------------------------------------------------------------------- -# Filter out hosts which are not ON +# Filter out hosts which are OFF, ERROR or DISABLED # @param $1 - space separated list of hosts -# @return - space separated list of hosts which are in ON state +# @return - space separated list of hosts which are not in OFF, ERROR or +# DISABLED sate #------------------------------------------------------------------------------- -function get_only_on_hosts { - INPUT_ARRAY=($1) +function remove_off_hosts { + ALL_HOSTS_ARRAY=($1) + OFF_HOSTS_STR=$(onehost list --no-pager --csv \ + --filter="STAT=off,STAT=err,STAT=dsbl" --list=NAME,STAT 2>/dev/null) - ONEHOST_LIST_ON_CMD='onehost list --no-pager --csv --filter="STAT=on" --list=NAME,STAT' - ON_HOSTS_STR=$(eval "$ONEHOST_LIST_ON_CMD 2>/dev/null") - - if [[ $? = 0 ]]; then - ON_HOSTS_ARRAY=($( echo "$ON_HOSTS_STR" | $AWK -F, '{ if (NR>1) print $1 }')) - for A in "${INPUT_ARRAY[@]}"; do - for B in "${ON_HOSTS_ARRAY[@]}"; do - [[ $A == $B ]] && { echo $A; break; } + if [ $? -eq 0 ]; then + OFF_HOSTS_ARRAY=($( echo "$OFF_HOSTS_STR" | awk -F, '{ if (NR>1) print $1 }')) + for HOST in "${ALL_HOSTS_ARRAY[@]}"; do + OFF=false + for OFF_HOST in "${OFF_HOSTS_ARRAY[@]}"; do + [ $HOST = $OFF_HOST ] && { OFF=true; break; } done + $OFF || echo -ne "$HOST " done else # onehost cmd failed, can't filter anything, better return unchanged @@ -483,8 +485,14 @@ function get_only_on_hosts { # @return host to be used as bridge #------------------------------------------------------------------------------- function get_destination_host { - BRIDGE_LIST=$(get_only_on_hosts "$BRIDGE_LIST") - HOSTS_ARRAY=($BRIDGE_LIST) + REDUCED_LIST=$(remove_off_hosts "$BRIDGE_LIST") + + if [ -z "$REDUCED_LIST" -a -n "$BRIDGE_LIST" ]; then + error_message "All hosts from 'BRIDGE_LIST' are offline, error or disabled" + exit -1 + fi + + HOSTS_ARRAY=($REDUCED_LIST) N_HOSTS=${#HOSTS_ARRAY[@]} if [ -n "$1" ]; then