summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@open-infrastructure.net>2016-12-11 11:06:53 +0000
committerDaniel Baumann <daniel.baumann@open-infrastructure.net>2016-12-11 12:13:00 +0000
commit456efbfa13fb43f8394291aa18e878d8d3acbda1 (patch)
treea3f360ec78170513659113f58cdebccdf5bd96b5
parentRemoving half-finished multi-address handling in container list command. (diff)
downloadcompute-tools-456efbfa13fb43f8394291aa18e878d8d3acbda1.tar.xz
compute-tools-456efbfa13fb43f8394291aa18e878d8d3acbda1.zip
Adding CSV export format to container list command.
Signed-off-by: Daniel Baumann <daniel.baumann@open-infrastructure.net>
-rwxr-xr-xlib/container/list26
-rw-r--r--share/bash-completion/container2
-rw-r--r--share/man/container-list.1.txt8
3 files changed, 32 insertions, 4 deletions
diff --git a/lib/container/list b/lib/container/list
index 453b46e..0347c78 100755
--- a/lib/container/list
+++ b/lib/container/list
@@ -23,9 +23,11 @@ COMMAND="$(basename ${0})"
CONFIG="/etc/container-tools/config"
MACHINES="/var/lib/machines"
+VERSION="$(container version)"
+
Parameters ()
{
- GETOPT_LONGOPTIONS="all,format:,host:,other,started,stopped,"
+ GETOPT_LONGOPTIONS="all,csv-separator:,format:,host:,other,started,stopped,"
GETOPT_OPTIONS="a,f:,h:,o,s,t,"
PARAMETERS="$(getopt --longoptions ${GETOPT_LONGOPTIONS} --name=${COMMAND} --options ${GETOPT_OPTIONS} --shell sh -- ${@})"
@@ -46,6 +48,11 @@ Parameters ()
shift 1
;;
+ --csv-separator)
+ CSV_SEPARATOR="${2}"
+ shift 2
+ ;;
+
-f|--format)
FORMAT="${2}"
shift 2
@@ -86,7 +93,7 @@ Parameters ()
Usage ()
{
- echo "Usage: container ${COMMAND} [-a|--all] [--format FORMAT] [-h|--host HOSTNAME] [-o|--other] [-s|--started] [-t|--stopped]" >&2
+ echo "Usage: container ${COMMAND} [-a|--all] [--csv-separator SEPARATOR] [--format FORMAT] [-h|--host HOSTNAME] [-o|--other] [-s|--started] [-t|--stopped]" >&2
exit 1
}
@@ -96,6 +103,8 @@ LIST="${LIST:-started stopped}"
FORMAT="${FORMAT:-cli}"
HOST="${HOST:-$(hostname -f)}"
+CSV_SEPARATOR="${CSV_SEPARATOR:-,}"
+
# Run
List ()
{
@@ -104,6 +113,10 @@ List ()
printf "%-80s %-29s\n" "${STATUS} ${BLUE}${CONTAINER}${NORMAL}" "${YELLOW}${ADDRESS}${NORMAL}"
;;
+ csv)
+ echo "${HOST}${CSV_SEPARATOR}${CONTAINER}${CSV_SEPARATOR}${STATE}${CSV_SEPARATOR}${ADDRESS}"
+ ;;
+
shell)
echo "${CONTAINER}"
;;
@@ -125,6 +138,15 @@ ${WHITE} ${NORMAL} Container IPv4 Address(e
EOF
;;
+
+ csv)
+
+cat << EOF
+# container-tools version ${VERSION}
+Host${CSV_SEPARATOR}Container${CSV_SEPARATOR}Status${CSV_SEPARATOR}IPv4-Address
+EOF
+
+ ;;
esac
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)"
diff --git a/share/bash-completion/container b/share/bash-completion/container
index 9dcdbc3..13bcdf3 100644
--- a/share/bash-completion/container
+++ b/share/bash-completion/container
@@ -139,7 +139,7 @@ _container()
;;
-f|--format)
- opts="cli shell"
+ opts="cli csv shell"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
;;
diff --git a/share/man/container-list.1.txt b/share/man/container-list.1.txt
index 53603db..3e4498b 100644
--- a/share/man/container-list.1.txt
+++ b/share/man/container-list.1.txt
@@ -46,8 +46,11 @@ The following container options are available, defaults to *--started --stopped*
*-a, --all*::
List all available container (started, stopped, and other).
+*--csv-separator='SEPARATOR'*::
+ Specify custom CSV separator, defaults to ','.
+
*-f, --format='FORMAT'*::
- Use format to list container. Currently available formats are 'cli' (default) or 'shell'.
+ Use format to list container. Currently available formats are 'cli' (default), 'csv', or 'shell'.
*-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.
@@ -69,6 +72,9 @@ EXAMPLES
*List all started and other containers:*::
sudo container list -s -o
+*Create a CSV export of all started and stopped containers:*::
+ sudo container list -f csv
+
*Create a shell export of all started and stopped containers:*::
sudo container list -f shell