-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathcompute_take_snapshot.sh
executable file
·54 lines (42 loc) · 1.45 KB
/
compute_take_snapshot.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
source /etc/slurm/openrc.sh
compute_image="$(hostname -s)-compute-image-latest"
compute_instance="compute-$(hostname -s)-base-instance"
openstack server stop ${compute_instance}
count=0
declare -i count
until [[ ${count} -ge 12 || "${shutoff_check}" =~ "SHUTOFF" ]];
do
shutoff_check=$(openstack server show -f value -c status ${compute_instance})
count+=1
sleep 5
done
image_check=$(openstack image show -f value -c name ${compute_image})
# If there is already a -latest image, re-name it with the date of its creation
if [[ -n ${image_check} ]];
then
old_image_date=$(openstack image show ${compute_image} -f value -c created_at | cut -d'T' -f 1)
backup_image_name=${compute_image::-7}-${old_image_date}
if [[ ${old_image_date} == "$(date +%Y-%m-%d)" && -n "$(openstack image show -f value -c name ${backup_image_name})" ]];
then
openstack image delete ${backup_image_name}
fi
openstack image set --name ${backup_image_name} ${compute_image}
fi
openstack server image create --name ${compute_image} ${compute_instance}
count=0
declare -i count
until [[ ${count} -ge 20 || "${instance_check}" =~ "active" ]];
do
instance_check=$(openstack image show -f value -c status ${compute_image})
count+=1
sleep 15
done
if [[ ${count} -ge 20 ]];
then
echo "Image still in queued status after 300 seconds"
exit 2
fi
echo "Done after ${count} sleeps."
openstack image list | grep $(hostname -s)
openstack server delete ${compute_instance}