#!/bin/bash

PSSH_RUN="pssh -i"

die() {
    echo "$1"
    exit ${2:-1}
}

set_pssh_hosts() {
    [ -z "$1" ] && die "No environment ID provided, exiting"
    for node in $(list_nodes $1 controller);
    do
        PSSH_RUN+=" -H $node"
    done
}

get_env_by_node() {
    [ -z "$1" ] && die "No node ID provided, exiting"
    echo "$(fuel node --node $1 \
        | awk -F\| '/^'$1'/ {gsub(" ", "", $4); print $4}')"
}

get_host_ip_by_node_id() {
    [ -z "$1" ] && die "No node ID provided, exiting"
    echo $(fuel node | awk -F"|" '/^'$1'/{print($5)}' | tr -d ' ')
}

get_last_node() {
    echo $(fuel node | awk -F\| '$1 ~ /[0-9]+[ ]+/{print($1)}' \
           | sort -n | tail -1)
}

get_node_online() {
    [ -z "$1" ] && die "No node ID provided, exiting"
    fuel node --node "$1" | tail -1 | awk -F\| '{gsub(" ", "", $9);print($9)}'
}

#!/bin/bash

die() {
    echo "$1"
    exit ${2:-1}
}

set_pssh_hosts() {
    [ -z "$1" ] && die "No environment ID provided, exiting"
    PSSH_RUN="pssh -i"
    for node in $(list_nodes $1 ${2:controller});
    do
        PSSH_RUN+=" -H $node"
    done
}

get_env_by_node() {
    [ -z "$1" ] && die "No node ID provided, exiting"
    echo "$(fuel node --node $1 \
        | awk -F\| '/^'$1'/ {gsub(" ", "", $4); print $4}')"
}

get_host_ip_by_node_id() {
    [ -z "$1" ] && die "No node ID provided, exiting"
    echo $(fuel node | awk -F"|" '/^'$1'/{print($5)}' | tr -d ' ')
}

get_last_node() {
    echo $(fuel node | awk -F\| '$1 ~ /[0-9]+[ ]+/{print($1)}' \
           | sort -n | tail -1)
}

get_node_online() {
    [ -z "$1" ] && die "No node ID provided, exiting"
    fuel node --node "$1" | tail -1 | awk -F\| '{gsub(" ", "", $9);print($9)}'
}

Set pssh hosts in runtime
Set pssh hosts in runtime

Although PSSH_RUN is global var, you need to set it's context before running
functions that use it to run pssh, and unset after using.
