summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xlib/container/list91
1 files changed, 77 insertions, 14 deletions
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