Skip to content

Commit 2f739a3

Browse files
author
charliefd
committed
First implementation of automatic naming. TIMEOUT is now configurable. Refs. #71950
1 parent 91add76 commit 2f739a3

3 files changed

Lines changed: 45 additions & 7 deletions

File tree

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ ENV IMAGE_NAME=EEA-docker-generic-v2.2 \
1010
INSTANCE_DOCKERSTORAGE_TYPE=standard \
1111
INSTANCE_DOCKER_VOLUME=true \
1212
INSTANCE_DOCKER_VOLUME_TYPE=standard \
13-
INSTANCE_DOCKER_VOLUME_SIZE=10
13+
INSTANCE_DOCKER_VOLUME_SIZE=10 \
14+
TIMEOUT=40
1415

1516

1617
RUN set -e \

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ Create a VM named prodXX-mil using defaults
4242
* OS_VOLUME_API_VERSION - API version for cinder. Defaults to 1
4343
* OS_AVAILABILITY_ZONE - openstack availability zone within the tenant (optional if the provider has only one zone or it uses same default for all services)
4444

45+
* TIMEOUT - how long shall we wait for volume or instance creation to succeed (in 10s of seconds)
46+
4547
* IMAGE_NAME - glance image to be used. defaults to EEA-docker-generic-v2.1 (should be already present in glance)
46-
* INSTANCE_NAME - provide a name for the new instance. A UUID will be generated if this is missing
48+
49+
* INSTANCE_NAME - provide a name for the new instance. It is considered a prefix if it ends with "-" and consecutive numbers are added to the name. A UUID will be generated if this is missing.
50+
4751
* INSTANCE_FLAVOR - name of the flavor to be used. defaults to a flavor named e2standard.x5 (should be already defined)
4852
* INSTANCE_ROOT_SIZE - self explanatory. defaults to 10 and is in GBytes
4953
* INSTANCE_ROOT_PERSISTENT - can be "true" or "false" (default). It sets the instance to delete all related volumes on termination

create_dockerhost.sh

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,40 @@ fi
99
#Sanity checks
1010
##########################
1111

12-
if [ x$INSTANCE_NAME = 'x' ]; then INSTANCE_NAME="$(python -c 'import sys,uuid; sys.stdout.write(uuid.uuid4().hex)')"; fi
12+
if [ x$INSTANCE_NAME = 'x' ]; then
13+
case "$OS_TENANT_NAME" in
14+
dev-env@eea.europa.eu)
15+
INSTANCE_NAME="dev-";;
16+
Soren.Roug@eea.europa.eu|Production)
17+
INSTANCE_NAME="prod-";;
18+
*)
19+
INSTANCE_NAME="$(python -c 'import sys,uuid; sys.stdout.write(uuid.uuid4().hex)')";;
20+
esac
21+
case "$OS_REGION_NAME" in
22+
it-mil1)
23+
INSTANCE_NAME=$INSTANCE_NAME"mil-";;
24+
nl-ams1)
25+
INSTANCE_NAME=$INSTANCE_NAME"ams-";;
26+
de-fra1)
27+
INSTANCE_NAME=$INSTANCE_NAME"fra-";;
28+
dk-cph1)
29+
INSTANCE_NAME=$INSTANCE_NAME"cph-";;
30+
*)
31+
INSTANCE_NAME="$(python -c 'import sys,uuid; sys.stdout.write(uuid.uuid4().hex)')";;
32+
esac
33+
fi
34+
35+
expr $INSTANCE_NAME : '.*-$'
36+
if [ $? == 0 ]; then
37+
lastno="$(nova list | awk -F '[-,|]' '/'$INSTANCE_NAME'/ {print $9}' | sort | tail -1)"
38+
expr $lastno : '[0-9][0-9]*$'
39+
if [ $? == 1 ] ; then
40+
lastno=0
41+
fi
42+
nextno=`printf "%02d" $((lastno+1))`
43+
INSTANCE_NAME=$INSTANCE_NAME$nextno
44+
fi
45+
1346

1447
nova list | grep $INSTANCE_NAME
1548
if [ $? == 0 ]; then
@@ -38,7 +71,7 @@ if [ x"$OS_AVAILABILITY_ZONE" != 'x' ]; then injectAVLcmd="--availability-zone";
3871
#########################
3972

4073
rootvol_id="$(cinder create --image-id $image_id --display-name $INSTANCE_NAME-Root --display-description 'Boot Volume based on '$IMAGE_NAME' image' $INSTANCE_ROOT_SIZE | awk '/\|[ ]+id[ ]+\|/ {print $4}')"
41-
i=40; vol_status=''
74+
i=$TIMEOUT; vol_status=''
4275
echo "Creating Root volume "$INSTANCE_NAME-Root
4376
while [ $((--i)) -gt 0 -a x$vol_status != 'xavailable' ]; do
4477
vol_status="$(cinder show $rootvol_id | awk '/\|[ ]+status/ {print $4}')"
@@ -62,7 +95,7 @@ if [ x"$INSTANCE_DOCKERSTORAGE_TYPE" != 'x' ]; then injectVTYPEcmd="--volume-typ
6295

6396
dsvol_id="$(cinder create $injectVTYPEcmd $INSTANCE_DOCKERSTORAGE_TYPE --display-name $INSTANCE_NAME-DockerStorage --display-description 'Docker storage' $INSTANCE_DOCKERSTORAGE_SIZE | awk '/\|[ ]+id[ ]+\|/ {print $4}')"
6497
echo "Creating Docker Storage volume "$INSTANCE_NAME-DockerStorage
65-
i=40; vol_status=''
98+
i=$TIMEOUT; vol_status=''
6699
while [ $((--i)) -gt 0 -a x$vol_status != 'xavailable' ]; do
67100
vol_status="$(cinder show $dsvol_id | awk '/\|[ ]+status/ {print $4}')"
68101
printf "\rWaiting to became available. Will timeout in %s" $((i*10))s
@@ -86,7 +119,7 @@ if [ x"$INSTANCE_DOCKER_VOLUME_TYPE" != 'x' ]; then injectVTYPEcmd="--volume-typ
86119
if [ $INSTANCE_DOCKER_VOLUME = true ]; then
87120
dvvol_id="$(cinder create $injectVTYPEcmd $INSTANCE_DOCKER_VOLUME_TYPE --display-name $INSTANCE_NAME-DockerVolumes --display-description 'Docker volumes' $INSTANCE_DOCKER_VOLUME_SIZE | awk '/\|[ ]+id[ ]+\|/ {print $4}')"
88121
echo "Creating Docker Volumes volume "$INSTANCE_NAME-DockerVolumes
89-
i=40; vol_status=''
122+
i=$TIMEOUT; vol_status=''
90123
while [ $((--i)) -gt 0 -a x$vol_status != 'xavailable' ]; do
91124
vol_status="$(cinder show $dvvol_id | awk '/\|[ ]+status/ {print $4}')"
92125
printf "\rWaiting to became available. Will timeout in %s" $((i*10))s
@@ -123,7 +156,7 @@ if [ $INSTANCE_DOCKER_VOLUME == true ]; then injectVOL2cmd="--block-device sourc
123156
cmd="nova boot --flavor $flavor_id $injectNETcmd $injectNetID$OS_NETWORK_ID --block-device source=volume,id=$rootvol_id,dest=volume,size=$INSTANCE_ROOT_SIZE,shutdown=remove,bootindex=0 --block-device source=volume,id=$dsvol_id,dest=volume,size=$INSTANCE_DOCKERSTORAGE_SIZE,shutdown=remove,bootindex=1 $injectVOL2cmd $injectAVLcmd $OS_AVAILABILITY_ZONE $injectKEY --user-data user_data.file $INSTANCE_NAME | awk '/\|[ ]+id[ ]+\|/ {print \$4}'"
124157
instance_id="$(eval $cmd)"
125158

126-
i=40; instance_status=''
159+
i=$TIMEOUT; instance_status=''
127160
while [ $((--i)) -gt 0 -a x$instance_status != 'xactive' ]; do
128161
instance_status="$(nova show $instance_id | awk '/vm_state/ {print $4}')"
129162
printf "\rWaiting to became active. Will timeout in %s" $((i*10))s

0 commit comments

Comments
 (0)