diff options
author | Daniel Baumann <daniel.baumann@open-infrastructure.net> | 2016-12-11 11:34:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@open-infrastructure.net> | 2016-12-11 12:13:00 +0000 |
commit | f64e4e06f0d06bde27e4dc8f030a7c92d5203c1e (patch) | |
tree | 0c454bda2a3ba956454ef7db164a14323913aaae /lib/container | |
parent | Adding JSON export format to container list command. (diff) | |
download | compute-tools-f64e4e06f0d06bde27e4dc8f030a7c92d5203c1e.tar.xz compute-tools-f64e4e06f0d06bde27e4dc8f030a7c92d5203c1e.zip |
Adding nwdiag export format to container list command.
Signed-off-by: Daniel Baumann <daniel.baumann@open-infrastructure.net>
Diffstat (limited to '')
-rwxr-xr-x | lib/container/list | 87 |
1 files changed, 85 insertions, 2 deletions
diff --git a/lib/container/list b/lib/container/list index a07b85b..45430a4 100755 --- a/lib/container/list +++ b/lib/container/list @@ -27,7 +27,7 @@ VERSION="$(container version)" Parameters () { - GETOPT_LONGOPTIONS="all,csv-separator:,format:,host:,other,started,stopped," + GETOPT_LONGOPTIONS="all,csv-separator:,format:,host:,nwdiag-color:,nwdiag-label:,other,started,stopped," GETOPT_OPTIONS="a,f:,h:,o,s,t," PARAMETERS="$(getopt --longoptions ${GETOPT_LONGOPTIONS} --name=${COMMAND} --options ${GETOPT_OPTIONS} --shell sh -- ${@})" @@ -63,6 +63,16 @@ Parameters () shift 2 ;; + --nwdiag-color) + NWDIAG_COLOR="${2}" + shift 2 + ;; + + --nwdiag-label) + NWDIAG_LABEL="${2}" + shift 2 + ;; + -o|--other) LIST="${LIST} other" shift 1 @@ -93,7 +103,7 @@ Parameters () Usage () { - echo "Usage: container ${COMMAND} [-a|--all] [--csv-separator SEPARATOR] [--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] [--nwdiag-color COLOR] [--nwdiag-label LABEL] [-o|--other] [-s|--started] [-t|--stopped]" >&2 exit 1 } @@ -129,12 +139,49 @@ EOF ;; + nwdiag) + Nwdiag_width "${CONTAINER}" + + case "${STATE}" in + started) + COLOR="#73d216" + ;; + + stopped) + COLOR="#cc0000" + ;; + + other) + COLOR="#d3d7cf" + ;; + esac + + echo " ${CONTAINER} [address = \"${ADDRESS}\", color = \"${COLOR}\", shape = \"flowchart.terminator\", width = \"${WIDTH}\"];" + ;; + shell) echo "${CONTAINER}" ;; esac } +Nwdiag_width () +{ + NAME="${1}" + + CHARACTERS="$(echo "${NAME}" | wc -c)" + + if [ "${CHARACTERS}" -gt 13 ] + then + # default width is 128 fitting 13 characters + WIDTH="$(( ${CHARACTERS} - 13 ))" + WIDTH="$(( ${WIDTH} * 5 ))" + WIDTH="$(( ${WIDTH} + 128 ))" + else + WIDTH="128" + fi +} + case "${FORMAT}" in cli) RED="$(tput setaf 1)$(tput bold)" @@ -174,6 +221,42 @@ cat << EOF EOF ;; + + nwdiag) + NETWORK="$(echo ${HOST} | sed -e 's|\.|_|g')" + +cat << EOF +# container-tools ${VERSION} +nwdiag { + external_connector = none; + network ${NETWORK} { +EOF + + if [ -n "${NWDIAG_LABEL}" ] + then + echo " label = \"${NWDIAG_LABEL}\"" + else + echo " label = \"\"" + fi + + NUMBER="$(${0} --format=short | wc -l)" + + if [ -n "${NWDIAG_COLOR}" ] + then + COLOR="${NWDIAG_COLOR}" + else + COLOR="#3465a4" + fi + + Nwdiag_width "${HOST}" + +cat << EOF + # host + ${HOST} [color = "${COLOR}", shape = "box", numbered = "${NUMBER}", width = "${WIDTH}"]; + # container +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)" |