From f41f3a347cace11dd2a9e6214f06d9acc75fc41e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Tue, 14 Jun 2016 21:20:28 +0200 Subject: Adding upstream version 20160615. Signed-off-by: Daniel Baumann --- lib/container/list | 91 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 77 insertions(+), 14 deletions(-) (limited to 'lib/container/list') diff --git a/lib/container/list b/lib/container/list index 8b55e09..7f64a18 100755 --- a/lib/container/list +++ b/lib/container/list @@ -20,12 +20,13 @@ set -e COMMAND="$(basename ${0})" +CONFIG="/etc/container-tools/config" MACHINES="/var/lib/machines" Parameters () { - LONG_OPTIONS="all,format:,started,stopped" - OPTIONS="a,f:,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 -- ${@})" @@ -50,6 +51,16 @@ Parameters () shift 2 ;; + -h|--host) + HOST="${2}" + shift 2 + ;; + + -o|--other) + LIST="other" + shift 1 + ;; + -s|--started) LIST="started" shift 1 @@ -83,6 +94,7 @@ Parameters "${@}" LIST="${LIST:-all}" FORMAT="${FORMAT:-full}" +HOST="${HOST:-$(hostname -f)}" # Run case "${FORMAT}" in @@ -91,10 +103,11 @@ case "${FORMAT}" in GREEN="$(tput setaf 2)$(tput bold)" YELLOW="$(tput setaf 3)$(tput bold)" BLUE="$(tput setaf 4)$(tput bold)" + WHITE="$(tput setaf 7)$(tput bold)" NORMAL="$(tput sgr0)" cat << EOF -Container IPv4 Address(es) Status + Container IPv4 Address(es) -------------------------------------------------------------------------------- EOF @@ -104,7 +117,7 @@ EOF ;; esac -CONTAINERS="$(cd "${MACHINES}" && find -maxdepth 1 -type d -and -not -name 'lost+found' -and -not -name '.snap' -and -not -name '.snapshot' -printf '%P\n' | sort)" +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} do @@ -116,21 +129,41 @@ do STATE="$(machinectl show ${CONTAINER} 2>&1 | awk -F= '/^State=/ { print $2 }')" + if [ -e "${CONFIG}/${CONTAINER}.conf" ] + then + AUTO="$(awk -F= '/^cnt.auto=/ { print $2 }' ${CONFIG}/${CONTAINER}.conf)" + AUTO="${AUTO:-false}" + + case "${AUTO}" in + ${HOST}|true) + ;; + + *) + STATE="other" + ;; + esac + else + STATE="other" + fi + if [ -e "${MACHINES}/${CONTAINER}/etc/network/interfaces" ] then ADDRESSES="$(awk '/address/ { print $2 }' ${MACHINES}/${CONTAINER}/etc/network/interfaces)" - else - ADDRESSES="n/a" fi + ADDRESSES="${ADDRESSES:-n/a}" + case "${STATE}" in running) - STATUS="${GREEN}started${NORMAL}" + STATUS="${GREEN}✔${NORMAL}" + ;; + other) + STATUS="${WHITE}○${NORMAL}" ;; *) - STATUS="${RED}stopped${NORMAL}" + STATUS="${RED}✘${NORMAL}" ;; esac @@ -149,11 +182,11 @@ do case "${FIRST_LINE}" in true) FIRST_LINE="false" - printf "%-69s %-29s %-7s\n" "${BLUE}${CONTAINER}${NORMAL}" "${YELLOW}${ADDRESS}${NORMAL}" " ${STATUS}" + printf "%-80s %-29s\n" "${STATUS} ${BLUE}${CONTAINER}${NORMAL}" "${YELLOW}${ADDRESS}${NORMAL}" ;; *) - printf "%-54s %-29s\n" "" "${ADDRESS}" + printf "%-80s %-29s\n" "" "${ADDRESS}" ;; esac done @@ -161,6 +194,36 @@ do esac ;; + 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 + ;; + started) case "${STATE}" in running) @@ -177,11 +240,11 @@ do case "${FIRST_LINE}" in true) FIRST_LINE="false" - printf "%-69s %-29s %-7s\n" "${BLUE}${CONTAINER}${NORMAL}" "${YELLOW}${ADDRESS}${NORMAL}" " ${STATUS}" + printf "%-80s %-29s\n" "${STATUS} ${BLUE}${CONTAINER}${NORMAL}" "${YELLOW}${ADDRESS}${NORMAL}" ;; *) - printf "%-54s %-29s\n" "" "${ADDRESS}" + printf "%-80s %-29s\n" "" "${ADDRESS}" ;; esac done @@ -210,11 +273,11 @@ do case "${FIRST_LINE}" in true) FIRST_LINE="false" - printf "%-69s %-29s %-7s\n" "${BLUE}${CONTAINER}${NORMAL}" "${YELLOW}${ADDRESS}${NORMAL}" " ${STATUS}" + printf "%-80s %-29s\n" "${STATUS} ${BLUE}${CONTAINER}${NORMAL}" "${YELLOW}${ADDRESS}${NORMAL}" ;; *) - printf "%-54s %-29s\n" "" "${ADDRESS}" + printf "%-80s %-29s\n" "" "${ADDRESS}" ;; esac done -- cgit v1.2.3