-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclone_one_xen_vm.sh
52 lines (39 loc) · 1.58 KB
/
clone_one_xen_vm.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
#!/bin/bash
set -o errexit
declare -A IP_ADDR # Create an associative array
IP_ADDR[tpc-tenant]=10.0.0.50
for VM in tenant;
do
echo "Cloning the tpc-${VM}";
if [[ ${VM} == g1a || ${VM} == g1b1 ]];
then
echo "Skiping the configured firsts VM"
continue
fi
test -e /dev/oxum-vg/tpc-${VM}-disk || lvcreate -L8G -n tpc-${VM}-disk oxum-vg
dd if=/dev/oxum-vg/tpc0-centos7-disk of=/dev/oxum-vg/tpc-${VM}-disk bs=512K
test -e /dev/oxum-vg/tpc-${VM}-swap ||lvcreate -L4G -n tpc-${VM}-swap oxum-vg
dd if=/dev/oxum-vg/tpc0-centos7-swap of=/dev/oxum-vg/tpc-${VM}-swap bs=512K
partprobe
kpartx -al /dev/oxum-vg/tpc-${VM}-disk
kpartx -al /dev/oxum-vg/tpc-${VM}-swap
mount /dev/mapper/oxum--vg-tpc--${VM}--disk1 /mnt/tpc-clone
cd /mnt/tpc-clone
sed -i "s/tpc0/tpc-${VM}/" etc/hostname
# adding the tpc hosts to the hosts files
fgrep '10.0.0.' /etc/hosts >> etc/hosts
sed -i "s/10.0.0.20/${IP_ADDR[tpc-${VM}]}/" etc/sysconfig/network-scripts/ifcfg-eth0
cd -
umount /mnt/tpc-clone
cd /var/tpcv/tpc_repo/xen_install/
cp tpc0-centos7.cfg tpc-${VM}-centos7.cfg
sed -i "s/tpc0/tpc-${VM}/g" tpc-${VM}-centos7.cfg
sed -i 's/-centos7//g' tpc-${VM}-centos7.cfg
sed -i "s/00:16:3E:29:QQ:QQ/$(bash gen-mac.sh)/" tpc-${VM}-centos7.cfg
if [[ ${VM} == g[[:digit:]]b* ]];
then
echo "Adding the dbstore space for the database VMs"
sed -i "s/xvdc,rw'/xvdc,rw',\n\t'phy:\/dev\/oxum-vg\/tpc_${VM}-dbstore,xvdd,rw'/" tpc-${VM}-centos7.cfg
fi
xl -vvv create tpc-${VM}-centos7.cfg
done