From 1d0e8aa25cd6fa974892c397fe46ae21efd03fb1 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 16 Jun 2016 08:10:09 +0200 Subject: Showing only local containers by default in container list command. Signed-off-by: Daniel Baumann --- lib/container/list | 179 ++++++++++++----------------------------- share/man/container-list.1.txt | 14 +++- 2 files changed, 62 insertions(+), 131 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 diff --git a/share/man/container-list.1.txt b/share/man/container-list.1.txt index 5474da4..0e3ea8a 100644 --- a/share/man/container-list.1.txt +++ b/share/man/container-list.1.txt @@ -39,10 +39,10 @@ The container list command lists container on the system. OPTIONS ------- -The following container options are available: +The following container options are available, defaults to *--started --stopped*: *-a, --all*:: - List all available container. + List all available container (started, stopped, and other). *-f, --format='FORMAT'*:: Use format to list container. Currently available formats are 'short' or 'full' (default). @@ -61,8 +61,14 @@ The following container options are available: EXAMPLES -------- -*List all started container on the the system as a machine-readable list:*:: - sudo container list --all --format=short +*List all started and stopped containers of the local system:*:: + sudo container list + +*List all started and stopped containers of the local system as a machine-readable list:*:: + sudo container list -f short + +*List all started and other containers:*:: + sudo container list -s -o SEE ALSO -- cgit v1.2.3