aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-02-20 17:05:46 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2018-02-21 10:32:58 +0100
commit49fb161d226bf3f77bf774ac65ebf1e95b6d1476 (patch)
treed12678ca564ae089c00056a857b70fb58249be83
parentdc1ac33bcfd55b9df2ad39e653a63a930d09af31 (diff)
Protect already taken IDs
Avoid user to choose an already taken ID at container creation Also display occupied ID list. Change-Id: Ic5094454097d5cbd9cbf01d2bb6eee24c8eafd8b Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rwxr-xr-xcontrib/create_container15
1 files changed, 14 insertions, 1 deletions
diff --git a/contrib/create_container b/contrib/create_container
index 01fc835..490886f 100755
--- a/contrib/create_container
+++ b/contrib/create_container
@@ -17,7 +17,9 @@
##########################################
CURDIR=$(cd $(dirname $0) && pwd -P)
+PREFIX=agl-worker
DEFIMAGE=$(make -s -C $CURDIR/.. show-image)
+OCCUPIED_ID=$(docker ps -a -f name=${PREFIX} --format "{{.Names}}" | grep -oE "[0-9]" | sort -n | sed ':a;N;$!ba;s/\n/ /g')
function usage() {
echo "Usage: $(basename $0) <instance ID> [image name]" >&2
@@ -39,7 +41,18 @@ IMAGE=${2:-$DEFIMAGE}
USER=$(id -un)
echo "Using instance ID #$ID (user $(id -un))"
-NAME=agl-worker-$(hostname|cut -f1 -d'.')-$ID-$USER
+NAME=${PREFIX}-$(hostname|cut -f1 -d'.')-$ID-$USER
+
+for n in $(docker ps -a -f name=${PREFIX} --format "{{.Names}}")
+do
+ if [ $NAME = $n ]
+ then
+ echo "This id is already taken."
+ echo "Please choose anohter one."
+ echo "Already taken id are: ${OCCUPIED_ID}"
+ exit 2
+ fi
+done
MIRRORDIR=$HOME/ssd/localmirror_$ID
XDTDIR=$HOME/ssd/xdt_$ID