summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@open-infrastructure.net>2016-06-14 19:09:39 +0000
committerDaniel Baumann <daniel.baumann@open-infrastructure.net>2016-06-14 19:09:39 +0000
commit3da5f515b3dd23a99a8da59d508834c87fa48650 (patch)
treeb9f4445ef6e67dfef0e20fe25536acf9039fb762
parentAdding bash-completion. (diff)
downloadcompute-tools-3da5f515b3dd23a99a8da59d508834c87fa48650.tar.xz
compute-tools-3da5f515b3dd23a99a8da59d508834c87fa48650.zip
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 <daniel.baumann@open-infrastructure.net>
Diffstat (limited to '')
-rwxr-xr-xlib/container/list84
-rw-r--r--share/man/container-list.1.txt3
2 files changed, 63 insertions, 24 deletions
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)
diff --git a/share/man/container-list.1.txt b/share/man/container-list.1.txt
index 77403a2..5474da4 100644
--- a/share/man/container-list.1.txt
+++ b/share/man/container-list.1.txt
@@ -50,6 +50,9 @@ The following container options are available:
*-h, --host='HOSTNAME'*::
List only container that are enabled for automatic start on the specified hostname. Defaults to list containers of the local system only. Using 'all' shows all container regardless of any automatic start configuration.
+*-h, --other*::
+ List only container that are not enable for automatic start on the current system.
+
*-s, --started*::
List only started container.