-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimage-deletion.sh
58 lines (38 loc) · 1.33 KB
/
image-deletion.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
55
56
57
#!/bin/bash
#
# Name : image-deletion.sh
# Description : Script for OF@TEIN Infrastructure Experiment Customs Image Deletion
#
# Created by : TEIN_GIST@nm.gist.ac.kr
# Version : 0.1
# Last Update : March, 2014
#
# Main Script
PARAMETER=2
if [ $# -ne $PARAMETER ]; then
echo -e ""
echo -e "Usage : ./image-deletion.sh <countryID> <vm_name> \n"
echo -e "countryID site name <GIST, MYREN, MY, ID, PH, VN ,TH, PKS>"
echo -e "vm_name Unique name (it will added with countryID)"
exit 0
else
# Check the VM name and Create if not exists
echo -e "Checking the VM Status ..."
VM=$(ssh tein@Smartx-BPlus-$1 "sudo xl list | grep $2")
if [ "$VM" = "" ]; then
echo -e "$2 Virtual Machine at $1 Site is not running ..."
echo -e "Delete $2 Virtual Machine at $1 Site ..."
ssh tein@Smartx-BPlus-$1 "sudo xen-delete-image --dir=images --hostname=$2-$1"
else
echo -e "$2-$1 Virtual machine is still running!!!"
echo -e "Try to stop the virtual machine"
ssh tein@Smartx-BPlus-$1 "sudo xl -f destroy $2-$1"
VM2=$(ssh tein@Smartx-BPlus-$1 "sudo xl list | grep $2-$1")
if [ "$VM2" = "" ]; then
echo -e "Delete $2 Virtual Machine at $1 Site ..."
ssh tein@Smartx-BPlus-$1 "sudo xen-delete-image --dir=images --hostname=$2-$1"
else
echo -e "$2-$1 Virtual machine can't be deleted!!!"
fi
fi
fi