summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2016-05-06 12:47:01 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2016-05-06 12:47:15 +0000
commit00c0021d891ffd42352a4acc5e389cc543f2779a (patch)
tree7a75b0f197f3371a6657866824e30dfe8bbb637a
parentReleasing debian version 20160415-1. (diff)
downloadopen-infrastructure-compute-tools-00c0021d891ffd42352a4acc5e389cc543f2779a.tar.xz
open-infrastructure-compute-tools-00c0021d891ffd42352a4acc5e389cc543f2779a.zip
Merging upstream version 20160501.
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
-rw-r--r--CHANGELOG.txt9
-rw-r--r--README.txt10
-rw-r--r--VERSION.txt2
-rwxr-xr-xbin/container-shell2
-rwxr-xr-xlib/container/list154
-rw-r--r--share/man/container-list.1.txt17
-rw-r--r--share/man/container-shell.1.txt2
-rw-r--r--share/man/container-tools.7.txt10
8 files changed, 177 insertions, 29 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 55c178c..eb5f83d 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,3 +1,10 @@
+2016-05-01 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+
+ * Releasing version 20160501.
+ * Adding multiple output formats in container list command.
+ * Adding status based listing of containers in container list command.
+ * Correcting errors in documentation.
+
2016-04-15 Daniel Baumann <daniel.baumann@open-infrastructure.net>
* Releasing version 20160415.
@@ -14,7 +21,7 @@
2016-04-01 Daniel Baumann <daniel.baumann@open-infrastructure.net>
* Releasing version 20160401.
- * Addding native ARM architecture support.
+ * Adding native ARM architecture support.
* Adding new container programs:
- container-autostart
- container-shell
diff --git a/README.txt b/README.txt
index 3627c2d..efc225d 100644
--- a/README.txt
+++ b/README.txt
@@ -31,7 +31,7 @@ systemd-nspawn.
2. git clone https://github.com/open-infrastructure/container-tools
3. cd container-tools && sudo make install
-3.2 Debian 8 (stretch) and newer
+3.2 Debian 9 (stretch) and newer
--------------------------------
* sudo apt install container-tools
@@ -40,7 +40,13 @@ systemd-nspawn.
4. Development
--------------
-Bug reports, feature requests, and patches are welcome. Please base them against the 'next' Git branch.
+Bug reports, feature requests, and patches are welcome via Github:
+
+ * https://github.com/open-infrastructure/container-tools
+
+Please base them against the 'next' Git branch using common sense:
+
+ * https://www.kernel.org/doc/Documentation/SubmittingPatches
5. Usage
diff --git a/VERSION.txt b/VERSION.txt
index 8460464..3eb848a 100644
--- a/VERSION.txt
+++ b/VERSION.txt
@@ -1 +1 @@
-20160415
+20160501
diff --git a/bin/container-shell b/bin/container-shell
index 4639537..fd85d93 100755
--- a/bin/container-shell
+++ b/bin/container-shell
@@ -49,7 +49,7 @@ Shell ()
return
;;
- logout)
+ logout|exit)
exit 0
;;
diff --git a/lib/container/list b/lib/container/list
index 110e6ea..5ab5755 100755
--- a/lib/container/list
+++ b/lib/container/list
@@ -22,46 +22,164 @@ COMMAND="$(basename ${0})"
MACHINES="/var/lib/machines"
+Parameters ()
+{
+ LONG_OPTIONS="all,format:,started,stopped"
+ OPTIONS="a,f:,s,t"
+
+ PARAMETERS="$(getopt --longoptions ${LONG_OPTIONS} --name=${COMMAND} --options ${OPTIONS} --shell sh -- ${@})"
+
+ if [ "${?}" != "0" ]
+ then
+ echo "'${COMMAND}': getopt exit" >&2
+ exit 1
+ fi
+
+ eval set -- "${PARAMETERS}"
+
+ while true
+ do
+ case "${1}" in
+ -a|--all)
+ LIST="all"
+ shift 1
+ ;;
+
+ -f|--format)
+ FORMAT="${2}"
+ shift 2
+ ;;
+
+ -s|--started)
+ LIST="started"
+ shift 1
+ ;;
+
+ -t|--stopped)
+ LIST="stopped"
+ shift 1
+ ;;
+
+ --)
+ shift 1
+ break
+ ;;
+
+ *)
+ echo "'${COMMAND}': getopt error" >&2
+ exit 1
+ ;;
+ esac
+ done
+}
+
Usage ()
{
- echo "Usage: container ${COMMAND}" >&2
+ echo "Usage: container ${COMMAND} -a|--all --format FORMAT -s|--started -t|--stopped" >&2
exit 1
}
-if [ -n "${1}" ]
-then
- Usage
-fi
+Parameters "${@}"
+
+LIST="${LIST:-all}"
+FORMAT="${FORMAT:-full}"
# Run
-CONTAINERS="$(cd "${MACHINES}" && find -maxdepth 1 -type d -and -not -name 'lost+found' -printf '%P\n' | sort)"
+case "${FORMAT}" in
+ full)
+ RED="$(tput setaf 1)$(tput bold)"
+ GREEN="$(tput setaf 2)$(tput bold)"
+ YELLOW="$(tput setaf 3)$(tput bold)"
+ BLUE="$(tput setaf 4)$(tput bold)"
+ NORMAL="$(tput sgr0)"
-echo RUNNING
+cat << EOF
+Container IPv4 Address Status
+--------------------------------------------------------------------------------
+EOF
+
+ ;;
+
+ short)
+ ;;
+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)"
for CONTAINER in ${CONTAINERS}
do
+ # FIXME: ignore lxc container for now
+ if [ -e "${MACHINES}/${CONTAINER}/rootfs" ]
+ then
+ continue
+ fi
+
STATE="$(machinectl show ${CONTAINER} 2>&1 | awk -F= '/^State=/ { print $2 }')"
+ if [ -e "${MACHINES}/${CONTAINER}/etc/network/interfaces" ]
+ then
+ ADDRESS="$(awk '/address/ { print $2 }' ${MACHINES}/${CONTAINER}/etc/network/interfaces)"
+ else
+ ADDRESS="n/a"
+ fi
+
case "${STATE}" in
running)
- echo " ${CONTAINER}"
+ STATUS="${GREEN}started${NORMAL}"
+
+ ;;
+
+ *)
+ STATUS="${RED}stopped${NORMAL}"
;;
esac
-done
-echo
-echo STOPPED
+ case "${LIST}" in
+ all)
+ case "${FORMAT}" in
+ short)
+ printf "${CONTAINER}\n"
+ ;;
-for CONTAINER in ${CONTAINERS}
-do
- STATE="$(machinectl show ${CONTAINER} 2>&1 | awk -F= '/^State=/ { print $2 }')"
+ full)
+ printf "%-72s %-29s %-7s\n" "${BLUE}${CONTAINER}${NORMAL}" "${YELLOW}${ADDRESS}${NORMAL}" "${STATUS}"
+ ;;
+ esac
+ ;;
- case "${STATE}" in
- running)
+ started)
+ case "${STATE}" in
+ running)
+ case "${FORMAT}" in
+ short)
+ printf "${CONTAINER}\n"
+ ;;
+
+ full)
+ printf "%-72s %-29s %-7s\n" "${BLUE}${CONTAINER}${NORMAL}" "${YELLOW}${ADDRESS}${NORMAL}" "${STATUS}"
+ ;;
+ esac
+ ;;
+ esac
;;
- *)
- echo " ${CONTAINER}"
+ stopped)
+ case "${STATE}" in
+ running)
+ ;;
+
+ *)
+ case "${FORMAT}" in
+ short)
+ printf "${CONTAINER}\n"
+ ;;
+
+ full)
+ printf "%-72s %-29s %-7s\n" "${BLUE}${CONTAINER}${NORMAL}" "${YELLOW}${ADDRESS}${NORMAL}" "${STATUS}"
+ ;;
+ esac
+ ;;
+ esac
;;
esac
done
diff --git a/share/man/container-list.1.txt b/share/man/container-list.1.txt
index 4dcbd78..e7015b7 100644
--- a/share/man/container-list.1.txt
+++ b/share/man/container-list.1.txt
@@ -39,13 +39,24 @@ The container list command lists container on the system.
OPTIONS
-------
-This command has no options.
+The following container options are available:
+*-a, --all*::
+ List all available container.
+
+*-f, --format='FORMAT'*::
+ Use format to list container. Currently available formats are 'short' or 'full' (default).
+
+*-s, --started*::
+ List only started container.
+
+*-t, --stopped*::
+ List only stopped container.
EXAMPLES
--------
-*List container on the the system:*::
- sudo container list
+*List all started container on the the system as a machine-readable list:*::
+ sudo container list --all --format=short
SEE ALSO
diff --git a/share/man/container-shell.1.txt b/share/man/container-shell.1.txt
index 9a2fdd8..dc60af2 100644
--- a/share/man/container-shell.1.txt
+++ b/share/man/container-shell.1.txt
@@ -50,7 +50,7 @@ All container commands are available, see container(1). Additionally, the follow
*help COMMAND:*::
shows help (manpage) for a specific container command.
-*logout:*::
+*logout*, *exit:*::
exits container-shell.
diff --git a/share/man/container-tools.7.txt b/share/man/container-tools.7.txt
index d8e5ac9..0e3e44d 100644
--- a/share/man/container-tools.7.txt
+++ b/share/man/container-tools.7.txt
@@ -51,7 +51,7 @@ SOURCE
2. git clone https://github.com/open-infrastructure/container-tools
3. cd container-tools && sudo make install
-DEBIAN 8 (STRETCH) AND NEWER
+DEBIAN 9 (STRETCH) AND NEWER
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* sudo apt install container-tools
@@ -60,7 +60,13 @@ DEBIAN 8 (STRETCH) AND NEWER
DEVELOPMENT
-----------
-Bug reports, feature requests, and patches are welcome. Please base them against the 'next' Git branch.
+Bug reports, feature requests, and patches are welcome via Github:
+
+ * https://github.com/open-infrastructure/container-tools
+
+Please base them against the 'next' Git branch using common sense:
+
+ * https://www.kernel.org/doc/Documentation/SubmittingPatches
USAGE