From 3da5f515b3dd23a99a8da59d508834c87fa48650 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Tue, 14 Jun 2016 21:09:39 +0200 Subject: Adding option to list only container that are not enable for automatic start on the current system in container list command. Signed-off-by: Daniel Baumann --- lib/container/list | 84 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 24 deletions(-) (limited to 'lib/container') diff --git a/lib/container/list b/lib/container/list index e19bfae..7f64a18 100755 --- a/lib/container/list +++ b/lib/container/list @@ -25,8 +25,8 @@ MACHINES="/var/lib/machines" Parameters () { - LONG_OPTIONS="all,format:,host:,started,stopped" - OPTIONS="a,f:,h:,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 -- ${@})" @@ -56,6 +56,11 @@ Parameters () shift 2 ;; + -o|--other) + LIST="other" + shift 1 + ;; + -s|--started) LIST="started" shift 1 @@ -98,6 +103,7 @@ 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 @@ -115,26 +121,6 @@ CONTAINERS="$(cd "${MACHINES}" 2>/dev/null && find -maxdepth 1 -type d -and -not for CONTAINER in ${CONTAINERS} do - if [ "${HOST}" != "all" ] - then - if [ -e "${CONFIG}/${CONTAINER}.conf" ] - then - AUTO="$(awk -F= '/^cnt.auto=/ { print $2 }' ${CONFIG}/${CONTAINER}.conf)" - AUTO="${AUTO:-false}" - - case "${AUTO}" in - ${HOST}|true) - ;; - - *) - continue - ;; - esac - else - continue - fi - fi - # FIXME: ignore lxc container for now if [ -e "${MACHINES}/${CONTAINER}/rootfs" ] then @@ -143,6 +129,23 @@ 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)" @@ -152,12 +155,15 @@ do case "${STATE}" in running) - STATUS="${GREEN}✓${NORMAL}" + STATUS="${GREEN}✔${NORMAL}" + ;; + other) + STATUS="${WHITE}○${NORMAL}" ;; *) - STATUS="${RED}✕${NORMAL}" + STATUS="${RED}✘${NORMAL}" ;; esac @@ -188,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) -- cgit v1.2.3