mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-20 10:50:08 +03:00
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
This commit is contained in:
parent
c5a89d57de
commit
948f929f6a
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user