diff options
author | Daniel Baumann <daniel.baumann@open-infrastructure.net> | 2016-06-16 06:10:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@open-infrastructure.net> | 2016-07-01 09:21:13 +0000 |
commit | 1d0e8aa25cd6fa974892c397fe46ae21efd03fb1 (patch) | |
tree | 2fb4baa708a783a96ce4d8424d157c3797901f7a /lib/container | |
parent | Releasing version 20160615. (diff) | |
download | compute-tools-1d0e8aa25cd6fa974892c397fe46ae21efd03fb1.tar.xz compute-tools-1d0e8aa25cd6fa974892c397fe46ae21efd03fb1.zip |
Showing only local containers by default in container list command.
Signed-off-by: Daniel Baumann <daniel.baumann@open-infrastructure.net>
Diffstat (limited to '')
-rwxr-xr-x | lib/container/list | 179 |
1 files changed, 52 insertions, 127 deletions
diff --git a/lib/container/list b/lib/container/list index 7f64a18..e5f7cd7 100755 --- a/lib/container/list +++ b/lib/container/list @@ -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 |