-
Notifications
You must be signed in to change notification settings - Fork 6
/
setup-compute.sh
executable file
·393 lines (353 loc) · 13.1 KB
/
setup-compute.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
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
#!/bin/sh
##
## Setup a OpenStack compute node for Nova.
##
set -x
# Gotta know the rules!
if [ $EUID -ne 0 ] ; then
echo "This script must be run as root" 1>&2
exit 1
fi
DIRNAME=`dirname $0`
# Grab our libs
. "$DIRNAME/setup-lib.sh"
if [ "$CONTROLLER" = "$HOSTNAME" -o "$NETWORKMANAGER" = "$HOSTNAME" ]; then
exit 0;
fi
if [ -f $OURDIR/setup-compute-done ]; then
exit 0
fi
logtstart "compute"
if [ -f $SETTINGS ]; then
. $SETTINGS
fi
#
# This is a nasty bug in oslo_service; see
# https://review.openstack.org/#/c/256267/
#
if [ $OSVERSION -ge $OSKILO ]; then
maybe_install_packages ${PYPKGPREFIX}-oslo.service
patch -d / -p0 < $DIRNAME/etc/oslo_service-liberty-sig-MAINLOOP.patch
fi
maybe_install_packages nova-compute sysfsutils
maybe_install_packages libguestfs-tools libguestfs0 python-guestfs
#
# Once we install packages, if the user wants a bigger VM disk space
# area, we make that and copy anything in /var/lib/nova into it (which
# may include stuff that was just installed). Then we bind mount it to
# /var/lib/nova .
#
ROOTDISK=
if [ -e /dev/sda ]; then
ROOTDISK=/dev/sda
ROOTDEV=sda
ROOTPART=4
elif [ -e /dev/nvme0n1 ]; then
ROOTDISK=/dev/nvme0n1
ROOTDEV=nvme0n1
ROOTPART=p4
fi
#
# Try to use LVM for this if possible; otherwise try to fall back to
# partition 4.
# Check to see if we already have an `emulab` VG. This would occur
# if the user requested a temp dataset. If this happens, we simple
# rename it to the VG name we expect.
#
mkdir -p /storage
vgdisplay emulab
if [ $? -eq 0 -a "$COMPUTE_EXTRA_NOVA_DISK_SPACE" = "1" ]; then
LVM=1
VGNAME="openstack-volumes"
vgrename emulab $VGNAME
sed -i -re "s/^(.*)(\/dev\/emulab)(.*)$/\1\/dev\/$VGNAME\3/" /etc/fstab
lvcreate -l 75%FREE -n nova $VGNAME
if [ -f /sbin/mkfs.ext4 ]; then
mkfs.ext4 /dev/$VGNAME/nova
else
mkfs.ext3 /dev/$VGNAME/nova
fi
mkdir -p /mnt/var-lib-nova
echo "/dev/$VGNAME/nova /mnt/var-lib-nova none defaults 0 0" \
>> /etc/fstab
mount /dev/$VGNAME/nova /mnt/var-lib-nova
chown nova:nova /mnt/var-lib-nova
rsync -avz /var/lib/nova/ /mnt/var-lib-nova/
mount -o bind /mnt/var-lib-nova /var/lib/nova
echo "/mnt/var-lib-nova /var/lib/nova none defaults,bind 0 0" \
>> /etc/fstab
elif [ "$COMPUTE_EXTRA_NOVA_DISK_SPACE" = "1" ]; then
#
# See if we can try to use an LVM instead of just the 4th partition.
#
lsblk -n -P -b -o NAME,FSTYPE,MOUNTPOINT,PARTTYPE,PARTUUID,TYPE,PKNAME,SIZE | perl -e 'my %devs = (); while (<STDIN>) { $_ =~ s/([A-Z0-9a-z]+=)/;\$$1/g; eval "$_"; if (!($TYPE eq "disk" || $TYPE eq "part")) { next; }; if (exists($devs{$PKNAME})) { delete $devs{$PKNAME}; } if ($FSTYPE eq "" && $MOUNTPOINT eq "" && ($PARTTYPE eq "" || $PARTTYPE eq "0x0") && (int($SIZE) > 3221225472)) { $devs{$NAME} = "/dev/$NAME"; } }; print join(" ",values(%devs))."\n"' > /tmp/devs
DEVS=`cat /tmp/devs`
if [ -n "$DEVS" ]; then
VGNAME="openstack-volumes"
pvcreate $DEVS
vgcreate $VGNAME $DEVS
lvcreate -l 75%FREE -n nova $VGNAME
if [ -f /sbin/mkfs.ext4 ]; then
mkfs.ext4 /dev/$VGNAME/nova
else
mkfs.ext3 /dev/$VGNAME/nova
fi
mkdir -p /mnt/var-lib-nova
echo "/dev/$VGNAME/nova /mnt/var-lib-nova none defaults 0 0" \
>> /etc/fstab
mount /dev/$VGNAME/nova /mnt/var-lib-nova
chown nova:nova /mnt/var-lib-nova
rsync -avz /var/lib/nova/ /mnt/var-lib-nova/
mount -o bind /mnt/var-lib-nova /var/lib/nova
echo "/mnt/var-lib-nova /var/lib/nova none defaults,bind 0 0" \
>> /etc/fstab
elif [ -e $ROOTDISK ]; then
PART="${ROOTDISK}${ROOTPART}"
mkdir -p /mnt/var-lib-nova
FORCEARG=""
if [ ! -e $PART ]; then
echo "*** WARNING: attempting to create max-size $PART from free space!"
START=`sfdisk -F $ROOTDISK | tail -1 | awk '{ print $1; }'`
SIZE=`sfdisk -F $ROOTDISK | tail -1 | awk '{ print $3; }'`
sfdisk -d $ROOTDISK > /tmp/nparts.out
if [ $? -eq 0 -a -s /tmp/nparts.out ]; then
echo "$PART : start=$START,size=$SIZE" >>/tmp/nparts.out
cat /tmp/nparts.out | sfdisk $ROOTDISK --force
if [ ! $? -eq 0 ]; then
echo "*** ERROR: failed to create new $PART!"
else
# Need to force mkextrafs.pl because sfdisk cannot set a
# partition type of 0, and mkextrafs.pl will only work
# normally with part-type 0.
FORCEARG="-f"
partprobe
sleep 10
fi
else
echo "*** ERROR: could not dump $PART partitions!"
fi
fi
/usr/local/etc/emulab/mkextrafs.pl $FORCEARG -r $ROOTDEV -s 4 /mnt/var-lib-nova
if [ $? = 0 ]; then
chown nova:nova /mnt/var-lib-nova
rsync -avz /var/lib/nova/ /mnt/var-lib-nova/
mount -o bind /mnt/var-lib-nova /var/lib/nova
echo "/mnt/var-lib-nova /var/lib/nova none defaults,bind 0 0" \
>> /etc/fstab
else
echo "*** ERROR: could not make larger Nova /var/lib/nova dir!"
fi
fi
fi
crudini --set /etc/nova/nova.conf DEFAULT auth_strategy keystone
crudini --set /etc/nova/nova.conf DEFAULT my_ip ${MGMTIP}
if [ $OSVERSION -lt $OSNEWTON ]; then
crudini --set /etc/nova/nova.conf glance host $CONTROLLER
else
crudini --set /etc/nova/nova.conf glance api_servers http://$CONTROLLER:9292
fi
crudini --set /etc/nova/nova.conf DEFAULT verbose ${VERBOSE_LOGGING}
crudini --set /etc/nova/nova.conf DEFAULT debug ${DEBUG_LOGGING}
if [ $OSVERSION -lt $OSKILO ]; then
crudini --set /etc/nova/nova.conf DEFAULT rpc_backend rabbit
crudini --set /etc/nova/nova.conf DEFAULT rabbit_host $CONTROLLER
crudini --set /etc/nova/nova.conf DEFAULT rabbit_userid ${RABBIT_USER}
crudini --set /etc/nova/nova.conf DEFAULT rabbit_password "${RABBIT_PASS}"
elif [ $OSVERSION -lt $OSNEWTON ]; then
crudini --set /etc/nova/nova.conf DEFAULT rpc_backend rabbit
crudini --set /etc/nova/nova.conf oslo_messaging_rabbit \
rabbit_host $CONTROLLER
crudini --set /etc/nova/nova.conf oslo_messaging_rabbit \
rabbit_userid ${RABBIT_USER}
crudini --set /etc/nova/nova.conf oslo_messaging_rabbit \
rabbit_password "${RABBIT_PASS}"
else
crudini --set /etc/nova/nova.conf DEFAULT transport_url $RABBIT_URL
fi
if [ $OSVERSION -lt $OSKILO ]; then
crudini --set /etc/nova/nova.conf keystone_authtoken \
auth_uri http://${CONTROLLER}:5000/v2.0
crudini --set /etc/nova/nova.conf keystone_authtoken \
identity_uri http://${CONTROLLER}:${KADMINPORT}
crudini --set /etc/nova/nova.conf keystone_authtoken \
admin_tenant_name service
crudini --set /etc/nova/nova.conf keystone_authtoken \
admin_user nova
crudini --set /etc/nova/nova.conf keystone_authtoken \
admin_password "${NOVA_PASS}"
else
crudini --set /etc/nova/nova.conf keystone_authtoken \
${AUTH_URI_KEY} http://${CONTROLLER}:5000
crudini --set /etc/nova/nova.conf keystone_authtoken \
auth_url http://${CONTROLLER}:${KADMINPORT}
crudini --set /etc/nova/nova.conf keystone_authtoken \
${AUTH_TYPE_PARAM} password
crudini --set /etc/nova/nova.conf keystone_authtoken \
${PROJECT_DOMAIN_PARAM} default
crudini --set /etc/nova/nova.conf keystone_authtoken \
${USER_DOMAIN_PARAM} default
crudini --set /etc/nova/nova.conf keystone_authtoken \
project_name service
crudini --set /etc/nova/nova.conf keystone_authtoken \
username nova
crudini --set /etc/nova/nova.conf keystone_authtoken \
password "${NOVA_PASS}"
fi
if [ $OSVERSION -ge $OSMITAKA -o $KEYSTONEUSEMEMCACHE -eq 1 ]; then
crudini --set /etc/nova/nova.conf keystone_authtoken \
memcached_servers ${CONTROLLER}:11211
fi
if [ $OSVERSION -ge $OSKILO ]; then
crudini --set /etc/nova/nova.conf oslo_concurrency \
lock_path /var/lib/nova/tmp
fi
if [ $OSVERSION -ge $OSOCATA ]; then
crudini --set /etc/nova/nova.conf placement \
os_region_name $REGION
crudini --set /etc/nova/nova.conf placement \
auth_url http://${CONTROLLER}:${KADMINPORT}/v3
crudini --set /etc/nova/nova.conf placement \
${AUTH_TYPE_PARAM} password
crudini --set /etc/nova/nova.conf placement \
${PROJECT_DOMAIN_PARAM} default
crudini --set /etc/nova/nova.conf placement \
${USER_DOMAIN_PARAM} default
crudini --set /etc/nova/nova.conf placement \
project_name service
crudini --set /etc/nova/nova.conf placement \
username placement
crudini --set /etc/nova/nova.conf placement \
password "${PLACEMENT_PASS}"
fi
if [ $OSVERSION -ge $OSLIBERTY -a $OSVERSION -lt $OSNEWTON ]; then
crudini --set /etc/nova/nova.conf enabled_apis 'osapi_compute,metadata'
crudini --set /etc/nova/nova.conf DEFAULT \
network_api_class nova.network.neutronv2.api.API
crudini --set /etc/nova/nova.conf DEFAULT \
security_group_api neutron
crudini --set /etc/nova/nova.conf DEFAULT \
linuxnet_interface_driver nova.network.linux_net.NeutronLinuxBridgeInterfaceDriver
fi
if [ $OSVERSION -ge $OSLIBERTY ]; then
crudini --set /etc/nova/nova.conf DEFAULT use_neutron True
crudini --set /etc/nova/nova.conf DEFAULT \
firewall_driver nova.virt.firewall.NoopFirewallDriver
fi
VNCSECTION="DEFAULT"
VNCENABLEKEY="vnc_enabled"
if [ $OSVERSION -ge $OSLIBERTY ]; then
VNCSECTION="vnc"
VNCENABLEKEY="enabled"
fi
cname=`getfqdn $CONTROLLER`
if [ $OSVERSION -lt $OSQUEENS ]; then
crudini --set /etc/nova/nova.conf $VNCSECTION \
vncserver_listen ${MGMTIP}
crudini --set /etc/nova/nova.conf $VNCSECTION \
vncserver_proxyclient_address ${MGMTIP}
else
crudini --set /etc/nova/nova.conf $VNCSECTION \
server_listen ${MGMTIP}
crudini --set /etc/nova/nova.conf $VNCSECTION \
server_proxyclient_address ${MGMTIP}
fi
#
# https://bugs.launchpad.net/nova/+bug/1635131
#
if [ $OSVERSION -ge $OSNEWTON ]; then
chost=`host $cname | sed -E -n -e 's/^(.* has address )(.*)$/\\2/p'`
crudini --set /etc/nova/nova.conf $VNCSECTION \
novncproxy_base_url "http://${chost}:6080/vnc_auto.html"
else
crudini --set /etc/nova/nova.conf $VNCSECTION \
novncproxy_base_url "http://${cname}:6080/vnc_auto.html"
fi
#
# Change $VNCENABLEKEY = True for x86 -- but for aarch64, there is
# no video device, for KVM mode, anyway, it seems.
#
ARCH=`uname -m`
if [ "$ARCH" = "aarch64" ] ; then
if [ $OSVERSION -le $OSKILO ]; then
crudini --set /etc/nova/nova.conf $VNCSECTION $VNCENABLEKEY False
else
# QEMU/Nova on Liberty gives aarch64 a vga adapter/bus.
crudini --set /etc/nova/nova.conf $VNCSECTION $VNCENABLEKEY True
fi
else
crudini --set /etc/nova/nova.conf $VNCSECTION $VNCENABLEKEY True
fi
if [ ${ENABLE_NEW_SERIAL_SUPPORT} = 1 ]; then
crudini --set /etc/nova/nova.conf serial_console enabled true
crudini --set /etc/nova/nova.conf serial_console listen $MGMTIP
crudini --set /etc/nova/nova.conf serial_console proxyclient_address $MGMTIP
crudini --set /etc/nova/nova.conf serial_console base_url ws://${cname}:6083/
fi
crudini --set /etc/nova/nova-compute.conf DEFAULT \
compute_driver libvirt.LibvirtDriver
crudini --set /etc/nova/nova-compute.conf libvirt virt_type kvm
if [ ${ENABLE_HOST_PASSTHROUGH} = 1 ]; then
# turn off MSR emulation
echo 1 > /sys/module/kvm/parameters/ignore_msrs
# persist the setting in case we reboot
echo "options kvm ignore_msrs=1" >> /etc/modprobe.d/qemu-system-x86.conf
# Set the "host-passthrough" mode for libvirt
crudini --set /etc/nova/nova-compute.conf libvirt cpu_mode host-passthrough
fi
if [ "$ARCH" = "aarch64" ] ; then
crudini --set /etc/nova/nova-compute.conf libvirt cpu_mode custom
crudini --set /etc/nova/nova-compute.conf libvirt cpu_model host
if [ $OSVERSION -ge $OSLIBERTY -a $OSVERSION -le $OSMITAKA ]; then
crudini --set /etc/nova/nova-compute.conf libvirt video_type vga
crudini --set /etc/nova/nova-compute.conf libvirt use_usb_tablet False
elif [ $OSVERSION -gt $OSMITAKA -a $OSVERSION -lt $OSPIKE ]; then
crudini --set /etc/nova/nova-compute.conf libvirt video_type vga
crudini --set /etc/nova/nova-compute.conf libvirt use_usb_tablet False
crudini --set /etc/nova/nova-compute.conf DEFAULT pointer_model ps2mouse
elif [ $OSVERSION -eq $OSPIKE ]; then
patch -d / -p0 < $DIRNAME/etc/nova-pike-aarch64-virtio-video.patch
crudini --set /etc/nova/nova-compute.conf libvirt video_type virtio
crudini --set /etc/nova/nova-compute.conf DEFAULT pointer_model ps2mouse
elif [ $OSVERSION -eq $OSQUEENS ]; then
patch -d / -p0 < $DIRNAME/etc/nova-queens-aarch64-libvirt-bios-default.patch
elif [ $OSVERSION -eq $OSROCKY ]; then
patch -d / -p0 < $DIRNAME/etc/nova-rocky-aarch64-libvirt-bios-default.patch
elif [ $OSVERSION -eq $OSSTEIN ]; then
patch -d / -p0 < $DIRNAME/etc/nova-stein-aarch64-libvirt-bios-default.patch
fi
elif [ "$ARCH" = "ppc64le" ] ; then
ppc64_cpu --smt=off
if [ -e /etc/rc.local ]; then
cat <<EOF >>/etc/rc.local
ppc64_cpu --smt=off
EOF
else
cat <<EOF >/etc/rc.local
#!/bin/sh
ppc64_cpu --smt=off
EOF
chmod 755 /etc/rc.local
fi
fi
if [ ${OSCODENAME} = "juno" ]; then
#
# Patch quick :(
#
patch -d / -p0 < $DIRNAME/etc/nova-juno-root-device-name.patch
fi
#
# Somewhere libvirt-guests.service defaulted to suspending the guests. Fix that.
#
if [ -f /etc/default/libvirt-guests ]; then
echo ON_SHUTDOWN=shutdown >> /etc/default/libvirt-guests
service_restart libvirt-guests
fi
service_restart nova-compute
service_enable nova-compute
service_restart libvirt-bin
service_enable libvirt-bin
# XXXX ???
# rm -f /var/lib/nova/nova.sqlite
touch $OURDIR/setup-compute-done
logtend "compute"
exit 0