-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtestsuite_deploy_vm.sh
executable file
·257 lines (235 loc) · 7.24 KB
/
testsuite_deploy_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/bin/sh
#########################################################
#
#
#########################################################
## INSTALL VM (and checks)
#########################################################
if [ -f `pwd`/functions ] ; then
. `pwd`/functions
else
echo "! need functions in current path; Exiting"; exit 1
fi
check_load_config_file
# global VAR
LIBVIRTPOOL="nodes_images"
DISKVM="${STORAGEP}/vm_xml.raw"
EXTRAARGS="autoyast=device://vdc/vm.xml"
if [ ! -f ${OTHERCDROM} ]; then echo "! ${OTHERCDROM} can not be found, needed for installation! fix this in ${CONF}. Exiting!" ; exit 1; fi
if [ ! -f ${SLECDROM} ]; then echo "! ${SLECDROM} can not be found, needed for installation! fix this in ${CONF}. Exiting!" ; exit 1; fi
# clean up previous VM
cleanup_vm() {
NAME="${NODENAME}"
echo $I "############ START cleanup_vm #############"
echo " !! WARNING !! "
echo " !! WARNING !! " $O
if [ -d ${STORAGEP}/${LIBVIRTPOOL} ]; then
echo "- This will remove previous VM guest image (in ${STORAGEP}/${LIBVIRTPOOL} dir)"
cd ${STORAGEP}/${LIBVIRTPOOL}
ls -1 ${NAME}*.qcow2
fi
echo
echo " press [ENTER] twice OR Ctrl+C to abort"
read
read
# for nb in `seq 1 $NBNODE`
for nb in `seq 1 ${NBNODE}`
do
GNAME="${NAME}${nb}"
virsh list --all | grep ${GNAME} > /dev/null
if [ $? == "0" ]; then
echo "- Destroy current VM: ${GNAME}"
virsh destroy ${GNAME}
echo "- Undefine current VM: ${GNAME}"
virsh undefine ${GNAME}
else
echo "- ${GNAME} is not present"
fi
echo "- Remove previous image file for VM ${GNAME} (${GNAME}.qcow2)"
rm -rvf ${STORAGEP}/${LIBVIRTPOOL}/${NAME}.qcow2
done
}
# Install VM 1
install_vm() {
echo $I "############ START install_vm #############" $O
# FIRST ARG MUST BE the MAC address
MAC=$1
# pool refresh to avoid error
virsh pool-refresh ${LIBVIRTPOOL}
echo "- Create new VM guest image file: ${NAME}.qcow2 ${IMAGESIZE}"
virsh vol-create-as --pool ${LIBVIRTPOOL} --name ${NAME}.qcow2 --capacity ${IMAGESIZE} --allocation ${IMAGESIZE} --format qcow2
virsh pool-refresh ${LIBVIRTPOOL}
if [ ! -f ${VMDISK} ]; then echo "- ${VMDISK} NOT present"; exit 1; fi
echo "- Start VM guest installation in a screen"
screen -d -m -S "install_VM_guest_${NAME}" virt-install --name ${NAME} \
--ram ${RAM} \
--vcpus ${VCPU} \
--virt-type kvm \
--os-variant sles12sp3 \
--controller scsi,model=virtio-scsi \
--network network=${NETWORKNAME},mac=${MAC} \
--graphics vnc,keymap=${KEYMAP} \
--disk path=${VMDISK},format=qcow2,bus=virtio,cache=none \
--disk path=${SHAREDISK},shareable=on,bus=virtio \
--disk path=${DISKVM},shareable=on,bus=virtio \
--disk path=${OTHERCDROM},shareable=on,device=cdrom \
--disk path=${SLECDROM},shareable=on,device=cdrom \
--location ${SLECDROM} \
--extra-args ${EXTRAARGS} \
--watchdog i6300esb,action=poweroff \
--console pty,target_type=virtio \
--rng /dev/urandom \
--check all=off
}
# --boot cdrom \
check_before_install() {
echo $I "############ START check_before_install #############" $O
if [ ! -f ${DISKVM} ]; then
echo "- ${DISKVM} NOT present, needed for auto installation"; exit 1
else
echo "- ${DISKVM} is present"
fi
if [ ! -f ${SHAREDISK} ]; then
echo "- ${SHAREDISK} NOT present, needed for share device"; exit 1
else
echo "- ${SHAREDISK} is present"
fi
}
copy_ssh_key() {
echo $I "- Don't forget to copy the root host SSH key to VM guest" $O
for NB in `seq 1 $NBNODE`
do
echo "ssh-copy-id -f -i /root/.ssh/${IDRSA}.pub -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ${NODENAME}${NB}"
done
echo
echo "- Clean up your /root/.ssh/known_hosts from previous config (dirty way below)
rm -vf /root/.ssh/known_hosts"
}
update_nb_nodes() {
((++NBNODE))
perl -pi -e "s/^NBNODE=.*/NBNODE=${NBNODE}/" $CONF
}
##########################
##########################
### MAIN
##########################
##########################
echo $I "####### PREPARE TO DEPLOY VM #########"
echo " !! WARNING !! "
echo " !! WARNING !! "
echo
echo "########################################"$O
case "$1" in
# CLEAN everything
cleanup)
cleanup_vm
;;
# create the pool
pool)
create_pool ${LIBVIRTPOOL}
;;
# verify everything is available
installvm)
check_before_install
# Install VM 1
NAME="${NODENAME}1"
VMDISK="${STORAGEP}/${LIBVIRTPOOL}/${NAME}.qcow2"
MAC=`(echo ${NODENAME}1|md5sum|sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/')`
install_vm ${MAC}
# install all other VM (minimal autoyast file)
# Use a minimal installation without X for node2 and node3 etc...
EXTRAARGS="autoyast=device://vdc/vm2.xml"
sleep 1
for nb in `seq 2 $NBNODE`
do
# Install VM
export NAME="${NODENAME}${nb}"
export VMDISK="${STORAGEP}/${LIBVIRTPOOL}/${NAME}.qcow2"
MAC=`(echo ${NODENAME}${nb}|md5sum|sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/')`
grep ${MAC} /etc/libvirt/qemu/networks/${NETWORKNAME}.xml
if [ "$?" -ne "0" ]; then
echo
echo " !!!! ${MAC} is missing from /etc/libvirt/qemu/networks/${NETWORKNAME}.xml !!!"
echo " !!!! EXPECT error in IP or Hostname for node ${NODENAME}${nb}"
echo
echo " PRESS ENTER TO CONTINUE"
read
fi
install_vm ${MAC}
sleep 1
done
;;
addvm)
# Install VM
if [ $# -lt 2 ];
then
echo ""
echo "! Please enter VM number! Exiting" ;
echo ""
echo "Currently VM deployed are:"
ls -1 ${STORAGEP}/${LIBVIRTPOOL}/${NAME}*.qcow2
exit 1;
fi
export NAME="${NODENAME}${2}"
export VMDISK="${STORAGEP}/${LIBVIRTPOOL}/${NAME}.qcow2"
MAC=`(echo ${NODENAME}${2}|md5sum|sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/')`
grep ${MAC} /etc/libvirt/qemu/networks/${NETWORKNAME}.xml
if [ "$?" -ne "0" ]; then
echo
echo " !!!! ${MAC} is missing from network pool /etc/libvirt/qemu/networks/${NETWORKNAME}.xml !!!"
echo " !!!! EXPECT error in IP or Hostname for node ${NODENAME}${2}"
fi
echo
echo " PRESS ENTER TO CONTINUE AND INSTALL VM ${NODENAME}${2}"
read
install_vm ${MAC}
update_nb_nodes
echo " You need to re-run some script to add you node in the host config and in the cluster service"
echo "./testsuite_host_conf.sh ssh"
echo "./testsuite_host_conf.sh pssh"
echo "./testsuite_init_cluster.sh hostname
scc
munge
slurm
nodeslist
sshkeynode
testuser
Dont forget to copy your ssh key id (ie: to node sle15sp35):
ssh-copy-id sle15sp35
Edit /root/.ssh/config and add your node in the list, ie:
host sle15sp31 sle15sp32 sle15sp33 sle15sp34 sle15sp35
IdentityFile /root/.ssh/id_rsa_SLE
"
;;
info)
# Check VM
virsh list
# Get IP address
virsh net-dhcp-leases ${NETWORKNAME}
# List installation in progress
screen -list
copy_ssh_key
;;
all)
cleanup
pool
installvm
info
;;
*)
echo "
Usage: $0 {cleanup|installvm|addvm|info|pool}
cleanup
delete all VM and VM storage
pool
create the pool storage for VM
installvm
install all VM ($NBNODE)
addvm
install one more VM (up to $MAXNBNODE)
info
display info about network, storage, ssh key etc...
"
exit 1
;;
esac