diff options
author | Daniel Baumann <mail@daniel-baumann.ch> | 2016-07-01 09:53:17 +0000 |
---|---|---|
committer | Daniel Baumann <mail@daniel-baumann.ch> | 2016-07-01 09:53:17 +0000 |
commit | a18674d73d1ef3472897c0f2049bf8131b9e4eb6 (patch) | |
tree | 0910f1df6e4648f6866cc06910314b845bf99bf1 /lib/container/list | |
parent | Adding upstream version 20160615. (diff) | |
download | open-infrastructure-compute-tools-upstream/20160701.tar.xz open-infrastructure-compute-tools-upstream/20160701.zip |
Adding upstream version 20160701.upstream/20160701
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'lib/container/list')
-rwxr-xr-x | lib/container/list | 183 |
1 files changed, 54 insertions, 129 deletions
diff --git a/lib/container/list b/lib/container/list index 7f64a18..60ae782 100755 --- a/lib/container/list +++ b/lib/container/list @@ -25,8 +25,8 @@ MACHINES="/var/lib/machines" Parameters () { - LONG_OPTIONS="all,format:,host:,other,started,stopped" - OPTIONS="a,f:,h:,o,s,t" + LONG_OPTIONS="all,format:,host:,other,started,stopped," + OPTIONS="a,f:,h:,o,s,t," PARAMETERS="$(getopt --longoptions ${LONG_OPTIONS} --name=${COMMAND} --options ${OPTIONS} --shell sh -- ${@})" @@ -42,7 +42,7 @@ Parameters () do case "${1}" in -a|--all) - LIST="all" + LIST="${LIST} all" shift 1 ;; @@ -57,17 +57,17 @@ Parameters () ;; -o|--other) - LIST="other" + LIST="${LIST} other" shift 1 ;; -s|--started) - LIST="started" + LIST="${LIST} started" shift 1 ;; -t|--stopped) - LIST="stopped" + LIST="${LIST} stopped" shift 1 ;; @@ -92,7 +92,7 @@ Usage () Parameters "${@}" -LIST="${LIST:-all}" +LIST="${LIST:-started stopped}" FORMAT="${FORMAT:-full}" HOST="${HOST:-$(hostname -f)}" @@ -107,7 +107,7 @@ case "${FORMAT}" in NORMAL="$(tput sgr0)" cat << EOF - Container IPv4 Address(es) +${WHITE} ${NORMAL} Container IPv4 Address(es) -------------------------------------------------------------------------------- EOF @@ -117,6 +117,33 @@ EOF ;; esac +Show () +{ + case "${FORMAT}" in + short) + printf "${CONTAINER}\n" + ;; + + full) + FIRST_LINE="true" + + for ADDRESS in ${ADDRESSES} + do + case "${FIRST_LINE}" in + true) + FIRST_LINE="false" + printf "%-80s %-29s\n" "${STATUS} ${BLUE}${CONTAINER}${NORMAL}" "${YELLOW}${ADDRESS}${NORMAL}" + ;; + + *) + printf "%-80s %-29s\n" "" "${ADDRESS}" + ;; + esac + done + ;; + esac +} + CONTAINERS="$(cd "${MACHINES}" 2>/dev/null && find -maxdepth 1 -type d -and -not -name '.container-tools' -and -not -name 'container-tools' -and -not -name 'lost+found' -and -not -name '.snap' -and -not -name '.snapshot' -printf '%P\n' | sort)" for CONTAINER in ${CONTAINERS} @@ -146,15 +173,9 @@ do STATE="other" fi - if [ -e "${MACHINES}/${CONTAINER}/etc/network/interfaces" ] - then - ADDRESSES="$(awk '/address/ { print $2 }' ${MACHINES}/${CONTAINER}/etc/network/interfaces)" - fi - - ADDRESSES="${ADDRESSES:-n/a}" - case "${STATE}" in running) + STATE="started" STATUS="${GREEN}✔${NORMAL}" ;; @@ -163,128 +184,32 @@ do ;; *) + STATE="stopped" STATUS="${RED}✘${NORMAL}" ;; esac - case "${LIST}" in - all) - case "${FORMAT}" in - short) - printf "${CONTAINER}\n" - ;; - - full) - FIRST_LINE="true" - - for ADDRESS in ${ADDRESSES} - do - case "${FIRST_LINE}" in - true) - FIRST_LINE="false" - printf "%-80s %-29s\n" "${STATUS} ${BLUE}${CONTAINER}${NORMAL}" "${YELLOW}${ADDRESS}${NORMAL}" - ;; - - *) - printf "%-80s %-29s\n" "" "${ADDRESS}" - ;; - esac - done - ;; - esac - ;; + if [ -e "${MACHINES}/${CONTAINER}/etc/network/interfaces" ] + then + ADDRESSES="$(awk '/address/ { print $2 }' ${MACHINES}/${CONTAINER}/etc/network/interfaces)" + fi - other) - case "${STATE}" in - other) - case "${FORMAT}" in - short) - printf "${CONTAINER}\n" - ;; - - full) - FIRST_LINE="true" - - for ADDRESS in ${ADDRESSES} - do - case "${FIRST_LINE}" in - true) - FIRST_LINE="false" - printf "%-80s %-29s\n" "${STATUS} ${BLUE}${CONTAINER}${NORMAL}" "${YELLOW}${ADDRESS}${NORMAL}" - ;; - - *) - printf "%-80s %-29s\n" "" "${ADDRESS}" - ;; - esac - done - ;; - esac - ;; - esac - ;; + ADDRESSES="${ADDRESSES:-n/a}" - started) - case "${STATE}" in - running) - case "${FORMAT}" in - short) - printf "${CONTAINER}\n" - ;; - - full) - FIRST_LINE="true" - - for ADDRESS in ${ADDRESSES} - do - case "${FIRST_LINE}" in - true) - FIRST_LINE="false" - printf "%-80s %-29s\n" "${STATUS} ${BLUE}${CONTAINER}${NORMAL}" "${YELLOW}${ADDRESS}${NORMAL}" - ;; - - *) - printf "%-80s %-29s\n" "" "${ADDRESS}" - ;; - esac - done - ;; - esac - ;; - esac - ;; + if echo ${LIST} | grep -qs all + then + Show + fi - stopped) + for ITEM in other started stopped + do + if echo ${LIST} | grep -qs ${ITEM} + then case "${STATE}" in - running) - ;; - - *) - case "${FORMAT}" in - short) - printf "${CONTAINER}\n" - ;; - - full) - FIRST_LINE="true" - - for ADDRESS in ${ADDRESSES} - do - case "${FIRST_LINE}" in - true) - FIRST_LINE="false" - printf "%-80s %-29s\n" "${STATUS} ${BLUE}${CONTAINER}${NORMAL}" "${YELLOW}${ADDRESS}${NORMAL}" - ;; - - *) - printf "%-80s %-29s\n" "" "${ADDRESS}" - ;; - esac - done - ;; - esac + ${ITEM}) + Show ;; esac - ;; - esac + fi + done done |