forked from beekhof/osp-ha-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
virt-hosts.scenario
415 lines (355 loc) · 11.6 KB
/
virt-hosts.scenario
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# This file can be used directly by 'phd', see 'build-all.sh' in this
# directory for how it can be invoked. The only requirement is a list
# of nodes you'd like it to modify.
#
# The scope of each command-block is controlled by the preceeding
# 'target' line.
#
# - target=all
# The commands are executed on evey node provided
#
# - target=local
# The commands are executed from the node hosting phd. When not
# using phd, they should be run from some other independant host
# (such as the puppet master)
#
# - target=$PHD_ENV_nodes{N}
# The commands are executed on the Nth node provided.
# For example, to run on only the first node would be target=$PHD_ENV_nodes1
#
# Tasks to be performed for the hosts include:
# - Install fence_virt so that the guests can be reset by other members of the virtualized clusters
# - Turning off auto-generation of resolv.conf so we can point to our gateway DNS server
# - Obtain the golden image from the first host
# - Clone the golden image for each service, inserting MAC addresses using the same rules as in the
#
# Tasks to be performed when creating the image include:
# - Installing CentOS 7
# - Pointing to the OpenStack, HA-Addon and Updates repositories
# - Ensuring cloned guests can obtain a DHCP lease
# - Ensuring consistent network interface names
# - Adding SSH keys if necessary
# - Configuring guests to obtain their hostname from DHCP
#################################
# Scenario Requirements Section #
#################################
= VARIABLES =
PHD_VAR_deployment
PHD_VAR_network_internal
PHD_VAR_network_nic_base
PHD_VAR_rpm_download
PHD_VAR_rpm_osp
PHD_VAR_rpm_rhel
PHD_VAR_vm_base
PHD_VAR_vm_cpus
PHD_VAR_vm_disk
PHD_VAR_vm_key
PHD_VAR_vm_ram
#################################
# Scenario Requirements Section #
#################################
= REQUIREMENTS =
nodes: 4
######################
# Deployment Scripts #
######################
= SCRIPTS =
target=all
....
if [ $(host $(hostname -s) | awk '{print $4}') != $(host $PHD_ENV_nodes1 | awk '{print $4}') ]; then
: Everyone except the first node needs to run the commands below
exit 0
fi
if grep -q srv /etc/fstab; then
echo /srv is already defined;
else
mkdir -p /srv
echo "${PHD_VAR_network_internal}.1:/srv /srv nfs defaults,v3 0 0" >> /etc/fstab
fi
mount -a
....
target=$PHD_ENV_nodes2 $PHD_ENV_nodes3 $PHD_ENV_nodes4
....
yum install -y fence-virtd fence-virtd-multicast fence-virtd-libvirt
lastoct="$(hostname -s | sed -e 's#^[a-z]*-##g' -e 's#^0*##g')"
cat > /etc/fence_virt.conf << EOF
fence_virtd {
listener = "multicast";
backend = "libvirt";
}
listeners {
multicast {
# key_file = "/etc/cluster/fence_xvm.key";
address = "225.0.0.$lastoct";
# Needed on Fedora systems
interface = "vmnet0";
}
}
backends {
libvirt {
uri = "qemu:///system";
}
}
EOF
if [ ! -e $PHD_VAR_env_configdir/fence_xvm.key ]; then
echo $(openssl rand -hex 10) > $PHD_VAR_env_configdir/fence_xvm.key
fi
cp $PHD_VAR_env_configdir/fence_xvm.key /etc/cluster/fence_xvm.key
# XXX remember to file a bug
chkconfig --add fence_virtd
chkconfig fence_virtd on
service fence_virtd start
....
target=$PHD_ENV_nodes1
....
if [ -e ${PHD_VAR_env_configdir}/${PHD_VAR_vm_base} ]; then
: skip this step if an image already exists
exit 0
fi
distro=${PHD_VAR_rpm_rhel}
distro_major=$(echo ${PHD_VAR_rpm_rhel} | awk -F. '{print $1}')
case ${distro_major} in
7) addons="addons/"; zstream="rhel-${distro}-z-build";;
*) addons=""; zstream="RHEL-${distro}-Z-build";;
esac
# headless - do not bork if we specify --noautoconsole
# reboot
# Do not specify --hostname= for network
# If prevents assinging by DHCP
cat << EOF > virt-base.ks
install
text
reboot
rootpw redhat
lang en_US.UTF-8
keyboard us
network --bootproto dhcp
firewall --enabled --ssh
selinux --permissive
timezone --utc Australia/Melbourne
bootloader --location=mbr --append="console=tty0 console=ttyS0,115200 rd_NO_PLYMOUTH serial text headless"
zerombr
clearpart --all --initlabel
autopart --type=lvm
skipx
%packages
@core
grep
gawk
bind-utils
vi
%end
%post
# ethX will do nicely thankyou
rm -f /lib/udev/rules.d/75-persistent-net-generator.rules
rm -f /etc/udev/rules.d/70-persistent-net.rules
# Need PEERDNS=no on the external interface to make sure all lookups
# go to our gateway (otherwise setting setting hostname via dhcp wont
# work)
#
# MUST add 'DEVICE=ethX' when deleting 'HWADDR', otherwise you end up
# with crazy things like:
#
# [root@localhost ~]# ifdown eth0
# Device 'eth1' successfully disconnected.
#
# Let eth0 come up, but don't let it connect to avoid conflicting dhcp
# and naming issues
#
# /usr/share/doc/initscripts/sysconfig.txt
cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOT
NAME="eth0"
DEVICE="eth0"
ONBOOT=yes
BOOTPROTO=none
TYPE=Ethernet
IPV4_FAILURE_FATAL=no
EOT
cat > /etc/sysconfig/network-scripts/ifcfg-eth1 << EOT
NAME="eth1"
DEVICE="eth1"
ONBOOT=yes
BOOTPROTO=dhcp
TYPE=Ethernet
EOT
# Prevent DHCPNAK by removing stale leases
# Occurs if we clone the guest and change NICs
rm -f /var/lib/NetworkManager/dhclient-*.lease
cat > /etc/yum.repos.d/rhel-${distro}.repo << EOT
[rhel-${distro}]
name=rhel-${distro}
baseurl=http://${PHD_VAR_rpm_download}/rel-eng/latest-RHEL-${distro_major}/compose/Server/\\\$basearch/os/
gpgcheck=0
enabled=1
[rhel-ha]
name=rhel-${distro}-ha
baseurl=http://${PHD_VAR_rpm_download}/rel-eng/latest-RHEL-${distro_major}/compose/Server/\\\$basearch/os/${addons}HighAvailability/
gpgcheck=0
enabled=1
[rhel-z]
name=rhel-${distro}-z
baseurl=http://${PHD_VAR_rpm_download}/brewroot/repos/${zstream}/latest/\\\$basearch/
gpgcheck=0
enabled=0
EOT
cat > /etc/yum.repos.d/osp-${PHD_VAR_rpm_osp}.repo << EOT
[OpenStack-${PHD_VAR_rpm_osp}-RHEL-${distro}-Puddle]
name=OpenStack-${PHD_VAR_rpm_osp}-RHEL-${distro}-Puddle
baseurl=http://${PHD_VAR_rpm_download}/rel-eng/OpenStack/${PHD_VAR_rpm_osp}-RHEL-${distro_major}${PHD_VAR_rpm_osp_beta}/latest/RH${distro_major}-RHOS-${PHD_VAR_rpm_osp}/\\\$basearch/os
gpgcheck=0
enabled=1
EOT
mkdir /root/.ssh
cat <<__EOT__ >> /root/.ssh/authorized_keys
ssh-rsa ${PHD_VAR_vm_key} admin
__EOT__
chmod 600 /root/.ssh/authorized_keys
%end
EOF
yum install -y virt-install
virsh destroy rhos6-rhel${distro_major}-base &>/dev/null
virsh undefine rhos6-rhel${distro_major}-base &>/dev/null
#Create the qcow2 disk image with preallocation and 'facllocate'(which pre-allocates all the blocks to a file) it for max. performance
echo "Creating qcow2 disk image.."
rm -f ${PHD_VAR_env_configdir}/${PHD_VAR_vm_base}
mkdir -p ${PHD_VAR_env_configdir}
qemu-img create -f qcow2 -o preallocation=metadata ${PHD_VAR_env_configdir}/${PHD_VAR_vm_base} ${PHD_VAR_vm_disk}
ls -lash ${PHD_VAR_env_configdir}/${PHD_VAR_vm_base}
#fallocate -l $(ls -al ${PHD_VAR_env_configdir}/${PHD_VAR_vm_base} | awk '{print $5}') ${PHD_VAR_env_configdir}/${PHD_VAR_vm_base}
#ls -lash ${PHD_VAR_env_configdir}/${PHD_VAR_vm_base}
# Turn off install logs
opts="--noautoconsole"
opts=""
# --console pty,target_type=virtio
#Create the regular-guest
virt-install --connect=qemu:///system \
--network=bridge:ext0,mac=${PHD_VAR_network_nic_base}:00:00:02 \
--initrd-inject=./virt-base.ks \
--extra-args="ks=file:/virt-base.ks console=tty0 console=ttyS0,115200 serial rd_NO_PLYMOUTH" \
--name=rhos6-rhel${distro_major}-base \
--disk path=${PHD_VAR_env_configdir}/${PHD_VAR_vm_base},format=qcow2,cache=none \
--ram ${PHD_VAR_vm_ram} \
--vcpus=${PHD_VAR_vm_cpus} \
--check-cpu \
--accelerate \
--os-type linux \
--os-variant rhel${distro_major} \
--cpuset auto \
--hvm \
--location=http://${PHD_VAR_rpm_download}/rel-eng/latest-RHEL-${distro_major}/compose/Server/x86_64/os/ \
--nographics $opts
# Needs 15-20 minutes apparently
sleep 1200
....
#target=$PHD_ENV_nodes1
#....
#virsh define /srv/vms/rhos4-base.xml
#virsh define /srv/rhos6-rhel7-vms/rhos6-rhel7-base.xml
#....
target=all
....
if [ $(host $(hostname -s) | awk '{print $4}') = $(host $PHD_ENV_nodes1 | awk '{print $4}') ]; then
: Everyone except the first node needs to run the commands below
exit 0
fi
mkdir -p /localvms
mkdir -p /allinone
# cp /srv/vms/rhos4-base.img /localvms/
if [ ! -e /localvms/${PHD_VAR_vm_base} ]; then
# This takes a loooong time, skip it if we already have an image
rsync -avz --progress ${PHD_VAR_env_configdir}/${PHD_VAR_vm_base} /localvms/
fi
....
target=all
....
if [ $(host $(hostname -s) | awk '{print $4}') = $(host $PHD_ENV_nodes1 | awk '{print $4}') ]; then
: Everyone except the first node needs to run the commands below
exit 0
fi
# The internal network must go first so that hostname can be set by
# DHCP and it will generally be the preferred network
#
# Random factoid, setting ONBOOT=no for eth0 will prevent eth1 from
# being started, even if eth1 has ONBOOT=yes
cat<<-EOF > /localvms/template.xml
<domain type='kvm'>
<name>VM_NAME</name>
<memory>${PHD_VAR_vm_ram}000</memory>
<currentMemory>${PHD_VAR_vm_ram}000</currentMemory>
<vcpu>${PHD_VAR_vm_cpus}</vcpu>
<os>
<type arch='x86_64' machine='pc'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/srv/rhos6-rhel7-vms/rhos6-rhel7-base.img'/>
<target dev='vda' bus='virtio'/>
</disk>
<interface type='bridge'>
<mac address='EXTERNAL_MAC'/>
<source bridge='ext0'/>
<model type='virtio'/>
</interface>
<interface type='bridge'>
<mac address='INTERNAL_MAC'/>
<source bridge='vmnet0'/>
<model type='virtio'/>
</interface>
<console type='pty'>
<target type='serial' port='0'/>
</console>
<input type='tablet' bus='usb'/>
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes'/>
</devices>
</domain>
EOF
sequence=16
lastoct="$(hostname -s | sed -e 's#^[a-z]*-##g' -e 's#^0*##g')"
offset="$(echo ${PHD_ENV_nodes1} | sed -e 's#\..*##g' -e 's#^[a-z]*-##g' -e 's#^0*##g')"
for section in ${PHD_VAR_components}; do
cd /localvms/
target=rhos6-${section}$(( ${lastoct} - ${offset} ))
octet=${sequence}
sequence=$((sequence + 1))
virsh destroy $target > /dev/null 2>&1
virsh undefine $target > /dev/null 2>&1
if [ $PHD_VAR_deployment = collapsed ]; then
case $section in
node) ;;
*)
# We don't need any of the other instances
# Its good to get rid of any old copies that might exist though
continue;;
esac
fi
cp template.xml ${target}.xml
sed -i.sed s#VM_NAME#${target}#g ${target}.xml
sed -i.sed s#EXTERNAL_MAC#${PHD_VAR_network_nic_base}:0${lastoct}:00:${octet}#g ${target}.xml
sed -i.sed s#INTERNAL_MAC#${PHD_VAR_network_nic_base}:0${lastoct}:01:${octet}#g ${target}.xml
sed -i.sed s:source\ file.*\/:source\ file=\'/localvms/${target}.cow\'\/:g ${target}.xml
diff -u template.xml ${target}.xml
rm -f /localvms/${target}.cow
qemu-img create -b /localvms/${PHD_VAR_vm_base} -f qcow2 /localvms/${target}.cow
virsh define ${target}.xml
if [ $? != 0 ]; then exit 1; fi
virsh start ${target}
if [ $? != 0 ]; then exit 1; fi
rm ${target}.xml.sed ${target}.xml
done
#truncate --size=10G /localvms/rhos6-swift-brick1_data.img
#truncate --size=10G /allinone/rhos6-node1_data.img
#truncate --size=10G /allinone/rhos6-mbayer1_data.img
....