-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimage-preparation.sh
65 lines (46 loc) · 1.96 KB
/
image-preparation.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
58
59
60
61
62
63
64
#!/bin/bash
#
# Name : image-preparation.sh
# Description : Script for OF@TEIN Infrastructure Experiment Customs Image Creation
#
# Created by : TEIN_GIST@nm.gist.ac.kr
# Version : 0.1
# Last Update : March, 2014
#
# Main Script
PARAMETER=5
if [ $# -ne $PARAMETER ]; then
echo -e ""
echo -e "Usage : ./image-preparation.sh <countryID> <vm_name> <ip_address> <netmask> <gateway> \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)"
echo -e "ip_address VM Management IP address"
echo -e "netmask VM Subnet Mask from Management IP address"
echo -e "vm_name VM Gateway IP address for access from outside\n"
exit 0
else
# Check the VM name and Create if not exists
echo -e "Checking the Running VM with the same name ..."
VM=$(ssh tein@Smartx-BPlus-$1 "sudo xl list | grep $2")
if [ "$VM" = "" ]; then
echo -e "Create $2 Virtual Machine at $1 Site ..."
ssh tein@Smartx-BPlus-$1 "sudo xen-create-image --hostname=$2-$1 --size=2Gb --noswap --ip=$3 --netmask=$4 --gateway=$5 --dir=images --memory=2Gb --arch=amd64 --dist=precise --install-method=tar --install-source=/opt/ubuntu-12.04.tar --genpass=0 --password=netmedia --bridge=xenbr0 --force"
ssh tein@Smartx-BPlus-$1 "cp /etc/xen/$2-$1.cfg ."
TEMP="\"s/xenbr0/xenbr0','ip=192.168.2.170,bridge=xenbr1/\""
ssh tein@Smartx-BPlus-$1 "sed -i $TEMP $2-$1.cfg"
else
echo -e "$2-$1 Virtual Machine already exists at $1 Site!!!"
echo -e "Please try use another hostname!!!"
exit 0
fi
echo -e "Starting the Virtual Machine $2-$1 at $1 Site"
ssh tein@SmartX-BPlus-$1 "sudo xl -f create $2-$1.cfg"
echo -e "Checking Virtual Machine $2-$1 is running ..."
VM=$(ssh tein@Smartx-BPlus-$1 "sudo xl list | grep $2")
if [ "$VM" = "" ]; then
echo -e "Virtual Machine at $2-$1 is not running !!! "
exit 0
else
echo -e "Virtual Machine at $2-$1 is running. "
fi
fi