blob: 905788f28f6721ce4c8d18bc27d0cafbe8795697 [file] [log] [blame]
Sean Daguee263c822014-12-05 14:25:28 -05001#!/bin/bash
2#
Dean Troyerbf67c192012-09-21 15:09:37 -05003# lib/nova
Dean Troyer6d04fd72012-12-21 11:03:37 -06004# Functions to control the configuration and operation of the **Nova** service
Dean Troyerbf67c192012-09-21 15:09:37 -05005
6# Dependencies:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01007#
8# - ``functions`` file
9# - ``DEST``, ``DATA_DIR``, ``STACK_USER`` must be defined
Marian Horban08abba02015-06-11 13:01:41 -040010# - ``FILES``
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010011# - ``SERVICE_{TENANT_NAME|PASSWORD}`` must be defined
12# - ``LIBVIRT_TYPE`` must be defined
13# - ``INSTANCE_NAME_PREFIX``, ``VOLUME_NAME_PREFIX`` must be defined
14# - ``KEYSTONE_TOKEN_FORMAT`` must be defined
Dean Troyerbf67c192012-09-21 15:09:37 -050015
16# ``stack.sh`` calls the entry points in this order:
17#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010018# - install_nova
19# - configure_nova
20# - create_nova_conf
21# - init_nova
22# - start_nova
23# - stop_nova
24# - cleanup_nova
Dean Troyerbf67c192012-09-21 15:09:37 -050025
26# Save trace setting
Ian Wienand523f4882015-10-13 11:03:03 +110027_XTRACE_LIB_NOVA=$(set +o | grep xtrace)
Dean Troyerbf67c192012-09-21 15:09:37 -050028set +o xtrace
29
Dean Troyerbf67c192012-09-21 15:09:37 -050030# Defaults
31# --------
32
33# Set up default directories
Sean Daguee08ab102014-11-13 17:09:28 -050034GITDIR["python-novaclient"]=$DEST/python-novaclient
Sergey Belous1258da62016-03-21 12:32:06 +030035GITDIR["os-vif"]=$DEST/os-vif
Dean Troyerbf67c192012-09-21 15:09:37 -050036NOVA_DIR=$DEST/nova
Dean Troyer4533eee2015-02-17 16:25:38 -060037
38# Nova virtual environment
39if [[ ${USE_VENV} = True ]]; then
40 PROJECT_VENV["nova"]=${NOVA_DIR}.venv
41 NOVA_BIN_DIR=${PROJECT_VENV["nova"]}/bin
42else
43 NOVA_BIN_DIR=$(get_python_exec_prefix)
44fi
45
Dean Troyerbf67c192012-09-21 15:09:37 -050046NOVA_STATE_PATH=${NOVA_STATE_PATH:=$DATA_DIR/nova}
47# INSTANCES_PATH is the previous name for this
48NOVA_INSTANCES_PATH=${NOVA_INSTANCES_PATH:=${INSTANCES_PATH:=$NOVA_STATE_PATH/instances}}
49
50NOVA_CONF_DIR=/etc/nova
51NOVA_CONF=$NOVA_CONF_DIR/nova.conf
Sean Dagueafc14c82017-07-27 07:09:48 -040052NOVA_COND_CONF=$NOVA_CONF_DIR/nova.conf
Dan Smithf3d53312017-06-08 08:22:38 -040053NOVA_CPU_CONF=$NOVA_CONF_DIR/nova-cpu.conf
Chris Dent2f27a0e2014-09-09 13:46:02 +010054NOVA_FAKE_CONF=$NOVA_CONF_DIR/nova-fake.conf
Dan Smith03786b12015-06-10 11:31:51 -070055NOVA_API_DB=${NOVA_API_DB:-nova_api}
Chris Dentb90bb1a2017-04-18 16:30:14 +000056NOVA_UWSGI=$NOVA_BIN_DIR/nova-api-wsgi
57NOVA_METADATA_UWSGI=$NOVA_BIN_DIR/nova-metadata-wsgi
58NOVA_UWSGI_CONF=$NOVA_CONF_DIR/nova-api-uwsgi.ini
59NOVA_METADATA_UWSGI_CONF=$NOVA_CONF_DIR/nova-metadata-uwsgi.ini
Kieran Spearfb2a3ae2013-03-11 23:55:49 +000060
Dan Smithf3d53312017-06-08 08:22:38 -040061# The total number of cells we expect. Must be greater than one and doesn't
62# count cell0.
63NOVA_NUM_CELLS=${NOVA_NUM_CELLS:-1}
64# Our cell index, so we know what rabbit vhost to connect to.
65# This should be in the range of 1-$NOVA_NUM_CELLS
66NOVA_CPU_CELL=${NOVA_CPU_CELL:-1}
67
Dean Troyerbf67c192012-09-21 15:09:37 -050068NOVA_API_PASTE_INI=${NOVA_API_PASTE_INI:-$NOVA_CONF_DIR/api-paste.ini}
69
Chris Dentb90bb1a2017-04-18 16:30:14 +000070# Toggle for deploying Nova-API under a wsgi server. We default to
71# true to use UWSGI, but allow False so that fall back to the
72# eventlet server can happen for grenade runs.
73# NOTE(cdent): We can adjust to remove the eventlet-base api service
74# after pike, at which time we can stop using NOVA_USE_MOD_WSGI to
75# mean "use uwsgi" because we'll be always using uwsgi.
76NOVA_USE_MOD_WSGI=${NOVA_USE_MOD_WSGI:-True}
Davanum Srinivasd5537c12015-04-30 21:10:48 -040077
Dan Smith3832ff52023-08-03 09:16:55 -070078# We do not need to report service status every 10s for devstack-like
79# deployments. In the gate this generates extra work for the services and the
80# database which are already taxed.
81NOVA_SERVICE_REPORT_INTERVAL=120
82
Sean Daguef3b2f4c2017-04-13 10:11:48 -040083if is_service_enabled tls-proxy; then
Rob Crittenden18d47782014-03-19 17:47:42 -040084 NOVA_SERVICE_PROTOCOL="https"
Rob Crittenden18d47782014-03-19 17:47:42 -040085fi
86
Daniel P. Berrangee9870eb2016-11-10 13:03:32 +000087# Whether to use TLS for comms between the VNC/SPICE/serial proxy
88# services and the compute node
89NOVA_CONSOLE_PROXY_COMPUTE_TLS=${NOVA_CONSOLE_PROXY_COMPUTE_TLS:-False}
90
Stephen Finucane8f3e51d2021-03-02 16:18:48 +000091# Validate configuration
92if ! is_service_enabled tls-proxy && [ "$NOVA_CONSOLE_PROXY_COMPUTE_TLS" == "True" ]; then
93 die $LINENO "enabling TLS for the console proxy requires the tls-proxy service"
94fi
95
Dean Troyer3a3a2ba2012-12-11 15:26:24 -060096# Public facing bits
97NOVA_SERVICE_HOST=${NOVA_SERVICE_HOST:-$SERVICE_HOST}
98NOVA_SERVICE_PORT=${NOVA_SERVICE_PORT:-8774}
99NOVA_SERVICE_PORT_INT=${NOVA_SERVICE_PORT_INT:-18774}
100NOVA_SERVICE_PROTOCOL=${NOVA_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
Jens Harbottdc7b4292017-09-19 10:52:32 +0000101NOVA_SERVICE_LISTEN_ADDRESS=${NOVA_SERVICE_LISTEN_ADDRESS:-$(ipv6_unquote $SERVICE_LISTEN_ADDRESS)}
Marian Horban08abba02015-06-11 13:01:41 -0400102METADATA_SERVICE_PORT=${METADATA_SERVICE_PORT:-8775}
Slawek Kaplonskid33cdd02019-08-01 14:58:37 +0200103NOVA_ENABLE_CACHE=${NOVA_ENABLE_CACHE:-True}
Dean Troyer3a3a2ba2012-12-11 15:26:24 -0600104
Ghanshyam Mann857f4992022-10-19 20:15:42 -0500105# Flag to set the oslo_policy.enforce_scope and oslo_policy.enforce_new_defaults.
Ghanshyam Mannbfa43972023-05-18 12:54:19 -0500106# This is used to disable the compute API policies scope and new defaults.
107# By Default, it is True.
Ghanshyam Mann857f4992022-10-19 20:15:42 -0500108# For more detail: https://docs.openstack.org/oslo.policy/latest/configuration/index.html#oslo_policy.enforce_scope
Ghanshyam Mannbfa43972023-05-18 12:54:19 -0500109NOVA_ENFORCE_SCOPE=$(trueorfalse True NOVA_ENFORCE_SCOPE)
Ghanshyam Mann857f4992022-10-19 20:15:42 -0500110
Gorka Eguileor97061c92021-10-14 09:55:56 +0200111if [[ $SERVICE_IP_VERSION == 6 ]]; then
112 NOVA_MY_IP="$HOST_IPV6"
113else
114 NOVA_MY_IP="$HOST_IP"
115fi
116
Dan Prince24f6efa2013-10-31 10:27:58 -0400117# Option to enable/disable config drive
Dean Troyerdc97cb72015-03-28 08:20:50 -0500118# NOTE: Set ``FORCE_CONFIG_DRIVE="False"`` to turn OFF config drive
Sean Dague7682ea82016-08-18 16:19:36 -0400119FORCE_CONFIG_DRIVE=${FORCE_CONFIG_DRIVE:-"False"}
Dan Prince24f6efa2013-10-31 10:27:58 -0400120
Artom Lifshitz47058612018-05-23 10:08:56 -0400121# The following NOVA_FILTERS contains SameHostFilter and DifferentHostFilter with
Ken'ichi Ohmichie0d61112015-12-17 08:47:46 +0000122# the default filters.
Sean Mooneyad029c02023-06-26 10:57:49 +0100123NOVA_FILTERS="ComputeFilter,ComputeCapabilitiesFilter,ImagePropertiesFilter,ServerGroupAntiAffinityFilter,ServerGroupAffinityFilter,SameHostFilter,DifferentHostFilter"
Ken'ichi Ohmichie0d61112015-12-17 08:47:46 +0000124
Dean Troyerbf67c192012-09-21 15:09:37 -0500125QEMU_CONF=/etc/libvirt/qemu.conf
126
Dean Troyerdc97cb72015-03-28 08:20:50 -0500127# ``NOVA_VNC_ENABLED`` can be used to forcibly enable VNC configuration.
128# In multi-node setups allows compute hosts to not run ``n-novnc``.
Sean Dague53753292014-12-04 19:38:15 -0500129NOVA_VNC_ENABLED=$(trueorfalse False NOVA_VNC_ENABLED)
Robbie Harwood (frozencemetery)4e07fdc2014-07-14 18:11:39 -0400130
Dean Troyer8c032d12013-09-23 13:53:13 -0500131# Get hypervisor configuration
132# ----------------------------
133
134NOVA_PLUGINS=$TOP_DIR/lib/nova_plugins
135if is_service_enabled nova && [[ -r $NOVA_PLUGINS/hypervisor-$VIRT_DRIVER ]]; then
136 # Load plugin
137 source $NOVA_PLUGINS/hypervisor-$VIRT_DRIVER
138fi
139
Pushkar Umaranikar14e16e42016-12-09 20:20:42 +0000140# Other Nova configurations
141# ----------------------------
142
143# ``NOVA_USE_SERVICE_TOKEN`` is a mode where service token is passed along with
144# user token while communicating to external RESP API's like Neutron, Cinder
145# and Glance.
Lee Yarwoodb516efe2021-02-15 10:11:43 +0000146NOVA_USE_SERVICE_TOKEN=$(trueorfalse True NOVA_USE_SERVICE_TOKEN)
Pushkar Umaranikar14e16e42016-12-09 20:20:42 +0000147
Stephen Finucane4b8cba72019-05-21 14:17:11 +0100148# ``NOVA_ALLOW_MOVE_TO_SAME_HOST`` can be set to False in multi node DevStack,
149# where there are at least two nova-computes.
150NOVA_ALLOW_MOVE_TO_SAME_HOST=$(trueorfalse True NOVA_ALLOW_MOVE_TO_SAME_HOST)
151
Ian Wienand8213d7c2019-02-11 12:28:15 +1100152# Enable debugging levels for iscsid service (goes from 0-8)
153ISCSID_DEBUG=$(trueorfalse False ISCSID_DEBUG)
154ISCSID_DEBUG_LEVEL=${ISCSID_DEBUG_LEVEL:-4}
155
Matt Riedemannb57757a2019-06-03 16:08:09 -0400156# Format for notifications. Nova defaults to "unversioned" since Train.
157# Other options include "versioned" and "both".
158NOVA_NOTIFICATION_FORMAT=${NOVA_NOTIFICATION_FORMAT:-unversioned}
159
Matt Riedemannd51baee2019-07-12 11:51:17 -0400160# Timeout for servers to gracefully shutdown the OS during operations
161# like shelve, rescue, stop, rebuild. Defaults to 0 since the default
162# image in devstack is CirrOS.
163NOVA_SHUTDOWN_TIMEOUT=${NOVA_SHUTDOWN_TIMEOUT:-0}
164
melanie witt099a0482021-05-06 00:09:33 +0000165# Whether to use Keystone unified limits instead of legacy quota limits.
166NOVA_USE_UNIFIED_LIMITS=$(trueorfalse False NOVA_USE_UNIFIED_LIMITS)
167
Dean Troyercc6b4432013-04-08 15:38:03 -0500168# Functions
169# ---------
Dean Troyerbf67c192012-09-21 15:09:37 -0500170
Dean Troyere4fa7212014-01-15 15:04:49 -0600171# Test if any Nova services are enabled
172# is_nova_enabled
173function is_nova_enabled {
Clark Boylan902158b2017-05-30 14:11:09 -0700174 [[ ,${DISABLED_SERVICES} =~ ,"nova" ]] && return 1
Dean Troyere4fa7212014-01-15 15:04:49 -0600175 [[ ,${ENABLED_SERVICES} =~ ,"n-" ]] && return 0
176 return 1
177}
178
Daniel P. Berrangee9870eb2016-11-10 13:03:32 +0000179# is_nova_console_proxy_compute_tls_enabled() - Test if the Nova Console Proxy
180# service has TLS enabled
181function is_nova_console_proxy_compute_tls_enabled {
182 [[ ${NOVA_CONSOLE_PROXY_COMPUTE_TLS} = "True" ]] && return 0
183 return 1
184}
185
Dean Troyerbf67c192012-09-21 15:09:37 -0500186# Helper to clean iptables rules
Ian Wienandaee18c72014-02-21 15:35:08 +1100187function clean_iptables {
Dean Troyerbf67c192012-09-21 15:09:37 -0500188 # Delete rules
189 sudo iptables -S -v | sed "s/-c [0-9]* [0-9]* //g" | grep "nova" | grep "\-A" | sed "s/-A/-D/g" | awk '{print "sudo iptables",$0}' | bash
190 # Delete nat rules
191 sudo iptables -S -v -t nat | sed "s/-c [0-9]* [0-9]* //g" | grep "nova" | grep "\-A" | sed "s/-A/-D/g" | awk '{print "sudo iptables -t nat",$0}' | bash
192 # Delete chains
193 sudo iptables -S -v | sed "s/-c [0-9]* [0-9]* //g" | grep "nova" | grep "\-N" | sed "s/-N/-X/g" | awk '{print "sudo iptables",$0}' | bash
194 # Delete nat chains
195 sudo iptables -S -v -t nat | sed "s/-c [0-9]* [0-9]* //g" | grep "nova" | grep "\-N" | sed "s/-N/-X/g" | awk '{print "sudo iptables -t nat",$0}' | bash
196}
197
198# cleanup_nova() - Remove residual data files, anything left over from previous
199# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100200function cleanup_nova {
Dean Troyerbf67c192012-09-21 15:09:37 -0500201 if is_service_enabled n-cpu; then
202 # Clean iptables from previous runs
203 clean_iptables
204
205 # Destroy old instances
Ian Wienandada886d2015-10-07 14:06:26 +1100206 local instances
207 instances=`sudo virsh list --all | grep $INSTANCE_NAME_PREFIX | sed "s/.*\($INSTANCE_NAME_PREFIX[0-9a-fA-F]*\).*/\1/g"`
Dean Troyerbf67c192012-09-21 15:09:37 -0500208 if [ ! "$instances" = "" ]; then
209 echo $instances | xargs -n1 sudo virsh destroy || true
Kevin Zhaocfc3edc2017-02-08 10:54:29 +0800210 if ! xargs -n1 sudo virsh undefine --managed-save --nvram <<< $instances; then
211 # Can't delete with nvram flags, then just try without this flag
212 xargs -n1 sudo virsh undefine --managed-save <<< $instances
213 fi
Dean Troyerbf67c192012-09-21 15:09:37 -0500214 fi
215
216 # Logout and delete iscsi sessions
Ian Wienandada886d2015-10-07 14:06:26 +1100217 local tgts
218 tgts=$(sudo iscsiadm --mode node | grep $VOLUME_NAME_PREFIX | cut -d ' ' -f2)
Dean Troyer0038a1a2014-07-25 15:27:54 -0500219 local target
Dan Smithc0fad2b2013-03-28 12:22:25 -0700220 for target in $tgts; do
221 sudo iscsiadm --mode node -T $target --logout || true
222 done
223 sudo iscsiadm --mode node --op delete || true
Dean Troyerbf67c192012-09-21 15:09:37 -0500224
Gorka Eguileor97061c92021-10-14 09:55:56 +0200225 # Disconnect all nvmeof connections
226 sudo nvme disconnect-all || true
227
Dean Troyerbf67c192012-09-21 15:09:37 -0500228 # Clean out the instances directory.
229 sudo rm -rf $NOVA_INSTANCES_PATH/*
230 fi
Dean Troyer995eb922013-03-07 16:11:40 -0600231
Dirk Mueller8ab64b32017-11-17 19:52:29 +0100232 sudo rm -rf $NOVA_STATE_PATH
Dean Troyer2aa2a892013-08-04 19:53:19 -0500233
234 # NOTE(dtroyer): This really should be called from here but due to the way
235 # nova abuses the _cleanup() function we're moving it
236 # directly into cleanup.sh until this can be fixed.
237 #if is_service_enabled n-cpu && [[ -r $NOVA_PLUGINS/hypervisor-$VIRT_DRIVER ]]; then
238 # cleanup_nova_hypervisor
239 #fi
Marian Horban13f65572015-06-10 14:34:22 -0400240
Chris Dentb90bb1a2017-04-18 16:30:14 +0000241 stop_process "n-api"
242 stop_process "n-api-meta"
243 remove_uwsgi_config "$NOVA_UWSGI_CONF" "$NOVA_UWSGI"
244 remove_uwsgi_config "$NOVA_METADATA_UWSGI_CONF" "$NOVA_METADATA_UWSGI"
Huan Xiong63beab52018-03-23 14:42:37 +0000245
246 if [[ "$NOVA_BACKEND" == "LVM" ]]; then
247 clean_lvm_volume_group $DEFAULT_VOLUME_GROUP_NAME
248 fi
Davanum Srinivasd5537c12015-04-30 21:10:48 -0400249}
250
Dean Troyerbf67c192012-09-21 15:09:37 -0500251# configure_nova() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100252function configure_nova {
Dean Troyerbf67c192012-09-21 15:09:37 -0500253 # Put config files in ``/etc/nova`` for everyone to find
Dean Troyer8421c2b2015-03-16 13:52:19 -0500254 sudo install -d -o $STACK_USER $NOVA_CONF_DIR
Dean Troyerbf67c192012-09-21 15:09:37 -0500255
Ian Wienandc6782412015-05-14 10:01:53 +1000256 configure_rootwrap nova
Dean Troyerbf67c192012-09-21 15:09:37 -0500257
Joe Gordonea70cc92014-11-25 19:07:11 -0800258 if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
Dean Troyerbf67c192012-09-21 15:09:37 -0500259 # Get the sample configuration file in place
260 cp $NOVA_DIR/etc/nova/api-paste.ini $NOVA_CONF_DIR
Dean Troyerbf67c192012-09-21 15:09:37 -0500261 fi
262
263 if is_service_enabled n-cpu; then
264 # Force IP forwarding on, just on case
265 sudo sysctl -w net.ipv4.ip_forward=1
266
Bob Ballb1e49bf2013-05-30 16:47:19 +0100267 if [[ "$VIRT_DRIVER" = 'libvirt' ]]; then
Bob Ballb1e49bf2013-05-30 16:47:19 +0100268 # Check for kvm (hardware based virtualization). If unable to initialize
269 # kvm, we drop back to the slower emulation mode (qemu). Note: many systems
270 # come with hardware virtualization disabled in BIOS.
271 if [[ "$LIBVIRT_TYPE" == "kvm" ]]; then
272 sudo modprobe kvm || true
273 if [ ! -e /dev/kvm ]; then
274 echo "WARNING: Switching to QEMU"
275 LIBVIRT_TYPE=qemu
Clark Boylane06d9542021-10-21 08:15:12 -0700276 LIBVIRT_CPU_MODE=custom
277 LIBVIRT_CPU_MODEL=Nehalem
Wei Jiangang91e3c1e2015-09-21 17:51:02 +0800278 if which selinuxenabled >/dev/null 2>&1 && selinuxenabled; then
Bob Ballb1e49bf2013-05-30 16:47:19 +0100279 # https://bugzilla.redhat.com/show_bug.cgi?id=753589
280 sudo setsebool virt_use_execmem on
281 fi
Dean Troyerbf67c192012-09-21 15:09:37 -0500282 fi
283 fi
Dean Troyerbf67c192012-09-21 15:09:37 -0500284
Bob Ballb1e49bf2013-05-30 16:47:19 +0100285 # Install and configure **LXC** if specified. LXC is another approach to
286 # splitting a system into many smaller parts. LXC uses cgroups and chroot
287 # to simulate multiple systems.
288 if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then
289 if is_ubuntu; then
Matt Riedemanndca06dc2015-08-20 13:56:57 -0700290 # enable nbd for lxc unless you're using an lvm backend
291 # otherwise you can't boot instances
292 if [[ "$NOVA_BACKEND" != "LVM" ]]; then
293 sudo modprobe nbd
294 fi
Dean Troyerbf67c192012-09-21 15:09:37 -0500295 fi
296 fi
297 fi
298
Dean Troyerbf67c192012-09-21 15:09:37 -0500299 # Instance Storage
300 # ----------------
301
302 # Nova stores each instance in its own directory.
Dean Troyer8421c2b2015-03-16 13:52:19 -0500303 sudo install -d -o $STACK_USER $NOVA_INSTANCES_PATH
Dean Troyerbf67c192012-09-21 15:09:37 -0500304
305 # You can specify a different disk to be mounted and used for backing the
306 # virtual machines. If there is a partition labeled nova-instances we
307 # mount it (ext filesystems can be labeled via e2label).
308 if [ -L /dev/disk/by-label/nova-instances ]; then
309 if ! mount -n | grep -q $NOVA_INSTANCES_PATH; then
310 sudo mount -L nova-instances $NOVA_INSTANCES_PATH
Attila Fazekas91b8d132013-01-06 22:40:09 +0100311 sudo chown -R $STACK_USER $NOVA_INSTANCES_PATH
Dean Troyerbf67c192012-09-21 15:09:37 -0500312 fi
313 fi
Ian Wienand8213d7c2019-02-11 12:28:15 +1100314
Gorka Eguileor97061c92021-10-14 09:55:56 +0200315 # Due to cinder bug #1966513 we ALWAYS need an initiator name for LVM
Lee Yarwood714826d2021-10-04 18:07:17 +0100316 # Ensure each compute host uses a unique iSCSI initiator
317 echo InitiatorName=$(iscsi-iname) | sudo tee /etc/iscsi/initiatorname.iscsi
318
Ian Wienand8213d7c2019-02-11 12:28:15 +1100319 if [[ ${ISCSID_DEBUG} == "True" ]]; then
320 # Install an override that starts iscsid with debugging
321 # enabled.
322 cat > /tmp/iscsid.override <<EOF
323[Service]
324ExecStart=
325ExecStart=/usr/sbin/iscsid -d${ISCSID_DEBUG_LEVEL}
326EOF
327 sudo mkdir -p /etc/systemd/system/iscsid.service.d
328 sudo mv /tmp/iscsid.override /etc/systemd/system/iscsid.service.d/override.conf
329 sudo systemctl daemon-reload
330 fi
331
Ade Leec3b70512021-08-06 14:26:37 -0400332 # set chap algorithms. The default chap_algorithm is md5 which will
Ade Leeac958692022-01-05 16:23:46 -0500333 # not work under FIPS.
Dr. Jens Harbott560ee162022-05-19 13:58:11 +0200334 iniset -sudo /etc/iscsi/iscsid.conf DEFAULT "node.session.auth.chap_algs" "SHA3-256,SHA256"
Ade Leec3b70512021-08-06 14:26:37 -0400335
Gorka Eguileor97061c92021-10-14 09:55:56 +0200336 if [[ $CINDER_TARGET_HELPER != 'nvmet' ]]; then
337 # ensure that iscsid is started, even when disabled by default
338 restart_service iscsid
339
340 # For NVMe-oF we need different packages that many not be present
341 else
342 install_package nvme-cli
343 sudo modprobe nvme-fabrics
344
345 # Ensure NVMe is ready and create the Soft-RoCE device over the networking interface
346 if [[ $CINDER_TARGET_PROTOCOL == 'nvmet_rdma' ]]; then
347 sudo modprobe nvme-rdma
348 iface=${HOST_IP_IFACE:-`ip -br -$SERVICE_IP_VERSION a | grep $NOVA_MY_IP | awk '{print $1}'`}
349 if ! sudo rdma link | grep $iface ; then
350 sudo rdma link add rxe_$iface type rxe netdev $iface
351 fi
352 elif [[ $CINDER_TARGET_PROTOCOL == 'nvmet_tcp' ]]; then
353 sudo modprobe nvme-tcp
354 else # 'nvmet_fc'
355 sudo modprobe nvme-fc
356 fi
357 fi
Dean Troyerbf67c192012-09-21 15:09:37 -0500358 fi
Dean Troyer8c032d12013-09-23 13:53:13 -0500359
360 # Rebuild the config file from scratch
361 create_nova_conf
362
Sergey Skripnicka99b8692014-03-05 14:47:58 +0200363 if is_service_enabled n-cpu && [[ -r $NOVA_PLUGINS/hypervisor-$VIRT_DRIVER ]]; then
Dean Troyer8c032d12013-09-23 13:53:13 -0500364 # Configure hypervisor plugin
365 configure_nova_hypervisor
366 fi
Dean Troyerbf67c192012-09-21 15:09:37 -0500367}
368
Dean Troyera0dce262012-12-11 16:52:37 -0600369# create_nova_accounts() - Set up common required nova accounts
Chris Dent67bc8e82014-10-08 12:07:46 +0100370#
Dean Troyer42a59c22014-03-03 14:31:29 -0600371# Project User Roles
Dean Troyera0dce262012-12-11 16:52:37 -0600372# ------------------------------------------------------------------
Sean Dague7580a0c2016-02-17 06:23:36 -0500373# SERVICE_PROJECT_NAME nova admin
374# SERVICE_PROJECT_NAME nova ResellerAdmin (if Swift is enabled)
Chris Dent67bc8e82014-10-08 12:07:46 +0100375function create_nova_accounts {
Dean Troyera0dce262012-12-11 16:52:37 -0600376
Dean Troyera0dce262012-12-11 16:52:37 -0600377 # Nova
378 if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100379
Jamie Lennoxe8bc2b82015-02-10 20:38:56 +1100380 # NOTE(jamielennox): Nova doesn't need the admin role here, however neutron uses
381 # this service user when notifying nova of changes and that requires the admin role.
Jamie Lennox85ff5322015-01-28 14:28:01 +1000382 create_service_user "nova" "admin"
Bartosz Górski0abde392014-02-28 14:15:19 +0100383
Sean Dague985e9582016-02-10 07:25:24 -0500384 local nova_api_url
385 if [[ "$NOVA_USE_MOD_WSGI" == "False" ]]; then
386 nova_api_url="$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT"
387 else
388 nova_api_url="$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST/compute"
Dean Troyera0dce262012-12-11 16:52:37 -0600389 fi
Sean Dague985e9582016-02-10 07:25:24 -0500390
391 get_or_create_service "nova_legacy" "compute_legacy" "Nova Compute Service (Legacy 2.0)"
Matt Riedemannae4578b2016-04-23 01:45:40 +0000392 get_or_create_endpoint \
Sean Dague985e9582016-02-10 07:25:24 -0500393 "compute_legacy" \
394 "$REGION_NAME" \
Sean Daguebd27cc22016-04-04 09:12:24 -0400395 "$nova_api_url/v2/\$(project_id)s"
Sean Dague985e9582016-02-10 07:25:24 -0500396
397 get_or_create_service "nova" "compute" "Nova Compute Service"
Matt Riedemannae4578b2016-04-23 01:45:40 +0000398 get_or_create_endpoint \
Sean Dague985e9582016-02-10 07:25:24 -0500399 "compute" \
400 "$REGION_NAME" \
Sean Dague7f87efd2015-10-09 10:07:11 -0400401 "$nova_api_url/v2.1"
Dean Troyera0dce262012-12-11 16:52:37 -0600402 fi
Dean Troyer42a59c22014-03-03 14:31:29 -0600403
404 if is_service_enabled n-api; then
405 # Swift
406 if is_service_enabled swift; then
407 # Nova needs ResellerAdmin role to download images when accessing
408 # swift through the s3 api.
Jamie Lennoxcbcbd8f2016-01-21 16:08:14 -0600409 get_or_add_user_project_role ResellerAdmin nova $SERVICE_PROJECT_NAME $SERVICE_DOMAIN_NAME $SERVICE_DOMAIN_NAME
Dean Troyer42a59c22014-03-03 14:31:29 -0600410 fi
Dean Troyer42a59c22014-03-03 14:31:29 -0600411 fi
412
413 # S3
Kota Tsuyuzaki070e4ee2018-09-13 03:08:19 +0900414 if is_service_enabled s3api; then
Sean Dague985e9582016-02-10 07:25:24 -0500415 get_or_create_service "s3" "s3" "S3"
Matt Riedemannae4578b2016-04-23 01:45:40 +0000416 get_or_create_endpoint \
Sean Dague985e9582016-02-10 07:25:24 -0500417 "s3" \
418 "$REGION_NAME" \
419 "http://$SERVICE_HOST:$S3_SERVICE_PORT" \
420 "http://$SERVICE_HOST:$S3_SERVICE_PORT" \
421 "http://$SERVICE_HOST:$S3_SERVICE_PORT"
Dean Troyer42a59c22014-03-03 14:31:29 -0600422 fi
melanie witt099a0482021-05-06 00:09:33 +0000423
424 # Unified limits
425 if is_service_enabled n-api; then
426 if [[ "$NOVA_USE_UNIFIED_LIMITS" = True ]]; then
427 configure_nova_unified_limits
428 fi
429 fi
Dean Troyera0dce262012-12-11 16:52:37 -0600430}
431
Dean Troyerda7b8092012-10-08 18:12:14 -0500432# create_nova_conf() - Create a new nova.conf file
Ian Wienandaee18c72014-02-21 15:35:08 +1100433function create_nova_conf {
Dean Troyerbf67c192012-09-21 15:09:37 -0500434 # Remove legacy ``nova.conf``
435 rm -f $NOVA_DIR/bin/nova.conf
436
437 # (Re)create ``nova.conf``
Dean Troyer3cf1ffb2012-10-02 11:51:27 -0500438 rm -f $NOVA_CONF
Ben Nemec03997942013-08-10 09:56:16 -0500439 iniset $NOVA_CONF DEFAULT debug "$ENABLE_DEBUG_LOG_LEVEL"
Joe Gordon18d62982014-10-28 13:37:15 -0700440 if [ "$NOVA_ALLOW_MOVE_TO_SAME_HOST" == "True" ]; then
441 iniset $NOVA_CONF DEFAULT allow_resize_to_same_host "True"
Joe Gordon18d62982014-10-28 13:37:15 -0700442 fi
Matt Riedemann38880982016-04-09 21:42:24 -0400443 iniset $NOVA_CONF wsgi api_paste_config "$NOVA_API_PASTE_INI"
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800444 iniset $NOVA_CONF DEFAULT rootwrap_config "$NOVA_CONF_DIR/rootwrap.conf"
Artom Lifshitz47058612018-05-23 10:08:56 -0400445 iniset $NOVA_CONF filter_scheduler enabled_filters "$NOVA_FILTERS"
Stephen Finucane65102e72020-05-27 14:24:09 +0100446 iniset $NOVA_CONF scheduler workers "$API_WORKERS"
Stephen Finucane283e86f2019-05-22 10:38:28 +0100447 iniset $NOVA_CONF neutron default_floating_pool "$PUBLIC_NETWORK_NAME"
Gorka Eguileor97061c92021-10-14 09:55:56 +0200448 iniset $NOVA_CONF DEFAULT my_ip "$NOVA_MY_IP"
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800449 iniset $NOVA_CONF DEFAULT instance_name_template "${INSTANCE_NAME_PREFIX}%08x"
Brian Haley180f5eb2015-06-16 13:14:31 -0400450 iniset $NOVA_CONF DEFAULT osapi_compute_listen "$NOVA_SERVICE_LISTEN_ADDRESS"
Brian Haley180f5eb2015-06-16 13:14:31 -0400451 iniset $NOVA_CONF DEFAULT metadata_listen "$NOVA_SERVICE_LISTEN_ADDRESS"
Matt Riedemannd51baee2019-07-12 11:51:17 -0400452 iniset $NOVA_CONF DEFAULT shutdown_timeout $NOVA_SHUTDOWN_TIMEOUT
Dean Troyerbf67c192012-09-21 15:09:37 -0500453
Kaitlin Farr8dd918c2017-10-24 09:34:03 -0400454 iniset $NOVA_CONF key_manager backend nova.keymgr.conf_key_mgr.ConfKeyManager
Kaitlin Farra5b72b02016-01-26 22:46:13 -0500455
Dan Smith3832ff52023-08-03 09:16:55 -0700456 iniset $NOVA_CONF DEFAULT report_interval $NOVA_SERVICE_REPORT_INTERVAL
457 iniset $NOVA_CONF DEFAULT service_down_time $(($NOVA_SERVICE_REPORT_INTERVAL * 6))
458
Martin Kopecec07b342023-01-24 17:38:45 +0100459 if is_fedora; then
460 # nova defaults to /usr/local/bin, but fedora pip like to
Ian Wienand00fd79d2013-06-06 11:19:16 +1000461 # install things in /usr/bin
462 iniset $NOVA_CONF DEFAULT bindir "/usr/bin"
463 fi
464
Slawek Kaplonskid33cdd02019-08-01 14:58:37 +0200465 # only setup database connections and cache backend if there are services
466 # that require them running on the host. The ensures that n-cpu doesn't
Sean Dague1b457c92017-01-18 07:53:33 -0500467 # leak a need to use the db in a multinode scenario.
468 if is_service_enabled n-api n-cond n-sched; then
Sean Dague5adfef02017-07-26 11:14:37 -0400469 # If we're in multi-tier cells mode, we want our control services pointing
470 # at cell0 instead of cell1 to ensure isolation. If not, we point everything
471 # at the main database like normal.
472 if [[ "$CELLSV2_SETUP" == "singleconductor" ]]; then
473 local db="nova_cell1"
474 else
475 local db="nova_cell0"
Matt Riedemannab980ce2017-08-01 16:38:42 -0400476 # When in superconductor mode, nova-compute can't send instance
477 # info updates to the scheduler, so just disable it.
478 iniset $NOVA_CONF filter_scheduler track_instance_changes False
Sean Dague5adfef02017-07-26 11:14:37 -0400479 fi
480
481 iniset $NOVA_CONF database connection `database_connection_url $db`
Sean Dague1b457c92017-01-18 07:53:33 -0500482 iniset $NOVA_CONF api_database connection `database_connection_url nova_api`
Slawek Kaplonskid33cdd02019-08-01 14:58:37 +0200483
484 # Cache related settings
485 # Those settings aren't really needed in n-cpu thus it is configured
486 # only on nodes which runs controller services
487 iniset $NOVA_CONF cache enabled $NOVA_ENABLE_CACHE
488 iniset $NOVA_CONF cache backend $CACHE_BACKEND
489 iniset $NOVA_CONF cache memcache_servers $MEMCACHE_SERVERS
Sean Dague1b457c92017-01-18 07:53:33 -0500490 fi
491
Dean Troyerbf67c192012-09-21 15:09:37 -0500492 if is_service_enabled n-api; then
Joe Gordond73af872014-02-06 15:33:52 -0800493 if is_service_enabled n-api-meta; then
494 # If running n-api-meta as a separate service
495 NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/,metadata//")
496 fi
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800497 iniset $NOVA_CONF DEFAULT enabled_apis "$NOVA_ENABLED_APIS"
Ghanshyam Mann857f4992022-10-19 20:15:42 -0500498 if [[ "$NOVA_ENFORCE_SCOPE" == "True" || "$ENFORCE_SCOPE" == "True" ]]; then
499 iniset $NOVA_CONF oslo_policy enforce_new_defaults True
500 iniset $NOVA_CONF oslo_policy enforce_scope True
Ghanshyam Mann69d71cf2023-01-10 20:13:47 -0600501 else
502 iniset $NOVA_CONF oslo_policy enforce_new_defaults False
503 iniset $NOVA_CONF oslo_policy enforce_scope False
Ghanshyam Mann857f4992022-10-19 20:15:42 -0500504 fi
Chris Dentb90bb1a2017-04-18 16:30:14 +0000505 if is_service_enabled tls-proxy && [ "$NOVA_USE_MOD_WSGI" == "False" ]; then
Dean Troyer3a3a2ba2012-12-11 15:26:24 -0600506 # Set the service port for a proxy to take the original
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800507 iniset $NOVA_CONF DEFAULT osapi_compute_listen_port "$NOVA_SERVICE_PORT_INT"
Rob Crittenden6254d5f2015-06-05 11:58:15 -0400508 iniset $NOVA_CONF DEFAULT osapi_compute_link_prefix $NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT
Dean Troyer3a3a2ba2012-12-11 15:26:24 -0600509 fi
Dan Prince741fc5c2013-10-16 17:48:16 -0400510
Dirk Mueller8ab64b32017-11-17 19:52:29 +0100511 configure_keystone_authtoken_middleware $NOVA_CONF nova
Dean Troyerbf67c192012-09-21 15:09:37 -0500512 fi
Dan Prince741fc5c2013-10-16 17:48:16 -0400513
Rob Crittenden18d47782014-03-19 17:47:42 -0400514 if is_service_enabled cinder; then
Matt Riedemann594885c2019-09-27 16:45:09 -0400515 configure_cinder_access
Rob Crittenden18d47782014-03-19 17:47:42 -0400516 fi
517
Dean Troyerbf67c192012-09-21 15:09:37 -0500518 if [ -n "$NOVA_STATE_PATH" ]; then
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800519 iniset $NOVA_CONF DEFAULT state_path "$NOVA_STATE_PATH"
Joe Gordon23d6d502015-03-06 15:24:22 -0800520 iniset $NOVA_CONF oslo_concurrency lock_path "$NOVA_STATE_PATH"
Dean Troyerbf67c192012-09-21 15:09:37 -0500521 fi
522 if [ -n "$NOVA_INSTANCES_PATH" ]; then
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800523 iniset $NOVA_CONF DEFAULT instances_path "$NOVA_INSTANCES_PATH"
Dean Troyerbf67c192012-09-21 15:09:37 -0500524 fi
Dean Troyerbf67c192012-09-21 15:09:37 -0500525 if [ "$SYSLOG" != "False" ]; then
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800526 iniset $NOVA_CONF DEFAULT use_syslog "True"
Dean Troyerbf67c192012-09-21 15:09:37 -0500527 fi
Dan Prince24f6efa2013-10-31 10:27:58 -0400528 if [ "$FORCE_CONFIG_DRIVE" != "False" ]; then
529 iniset $NOVA_CONF DEFAULT force_config_drive "$FORCE_CONFIG_DRIVE"
530 fi
Dirk Muellerc1144492018-04-11 21:33:50 +0200531
532 # nova defaults to genisoimage but only mkisofs is available for 15.0+
Alfredo Moralejo5ea4c3c2021-11-16 15:13:03 +0100533 # rhel provides mkisofs symlink to genisoimage or xorriso appropiately
Martin Kopecec07b342023-01-24 17:38:45 +0100534 if is_fedora; then
Dirk Muellerc1144492018-04-11 21:33:50 +0200535 iniset $NOVA_CONF DEFAULT mkisofs_cmd /usr/bin/mkisofs
536 fi
537
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700538 # Format logging
Chris Dentb90bb1a2017-04-18 16:30:14 +0000539 setup_logging $NOVA_CONF
Sean Dague9751be62016-04-05 12:08:57 -0400540
Matt Riedemann21221d12018-03-06 10:08:36 -0500541 iniset $NOVA_CONF upgrade_levels compute "auto"
542
Lee Yarwoodfc8ef862021-03-09 17:32:25 +0000543 if is_service_enabled n-api; then
544 write_uwsgi_config "$NOVA_UWSGI_CONF" "$NOVA_UWSGI" "/compute"
545 fi
546
547 if is_service_enabled n-api-meta; then
548 write_uwsgi_config "$NOVA_METADATA_UWSGI_CONF" "$NOVA_METADATA_UWSGI" "" "$SERVICE_LISTEN_ADDRESS:${METADATA_SERVICE_PORT}"
549 fi
Davanum Srinivasd5537c12015-04-30 21:10:48 -0400550
Eoghan Glynn1fcc6a12012-10-25 14:57:14 +0000551 if is_service_enabled ceilometer; then
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800552 iniset $NOVA_CONF DEFAULT instance_usage_audit "True"
553 iniset $NOVA_CONF DEFAULT instance_usage_audit_period "hour"
Julien Danjoua9787d02013-07-02 11:30:40 +0200554 iniset $NOVA_CONF DEFAULT notify_on_state_change "vm_and_task_state"
Eoghan Glynn1fcc6a12012-10-25 14:57:14 +0000555 fi
556
Gregory Haynes14d86e82016-07-29 03:45:37 +0000557 # Set the oslo messaging driver to the typical default. This does not
558 # enable notifications, but it will allow them to function when enabled.
Matt Riedemann45da7772017-03-05 13:07:39 -0500559 iniset $NOVA_CONF oslo_messaging_notifications driver "messagingv2"
Kenneth Giustib6459042017-08-04 18:08:37 -0400560 iniset $NOVA_CONF oslo_messaging_notifications transport_url $(get_notification_url)
Matt Riedemannb57757a2019-06-03 16:08:09 -0400561 iniset $NOVA_CONF notifications notification_format "$NOVA_NOTIFICATION_FORMAT"
Brant Knudson2dd110c2015-03-14 12:39:14 -0500562 iniset_rpc_backend nova $NOVA_CONF
Bob Ball2f720502014-08-28 14:50:04 +0100563
Joe Gordon1f79bad2014-09-26 09:59:47 -0700564 iniset $NOVA_CONF DEFAULT osapi_compute_workers "$API_WORKERS"
Dean Troyer05bd7b82014-09-16 17:25:33 -0500565 iniset $NOVA_CONF DEFAULT metadata_workers "$API_WORKERS"
Sean Dague1ce19ab2015-09-23 10:36:53 -0400566 # don't let the conductor get out of control now that we're using a pure python db driver
567 iniset $NOVA_CONF conductor workers "$API_WORKERS"
Rob Crittenden18d47782014-03-19 17:47:42 -0400568
Sean Daguef3b2f4c2017-04-13 10:11:48 -0400569 if is_service_enabled tls-proxy; then
Rob Crittenden18d47782014-03-19 17:47:42 -0400570 iniset $NOVA_CONF DEFAULT glance_protocol https
Jens Harbott411c34d2017-08-29 14:40:26 +0000571 iniset $NOVA_CONF oslo_middleware enable_proxy_headers_parsing True
Rob Crittenden18d47782014-03-19 17:47:42 -0400572 fi
573
Marian Horban7159b4b2015-10-22 15:47:49 -0400574 iniset $NOVA_CONF DEFAULT graceful_shutdown_timeout "$SERVICE_GRACEFUL_SHUTDOWN_TIMEOUT"
Davanum Srinivasac8ff0f2016-01-13 17:28:43 -0500575
Pushkar Umaranikar14e16e42016-12-09 20:20:42 +0000576 if [ "$NOVA_USE_SERVICE_TOKEN" == "True" ]; then
577 init_nova_service_user_conf
578 fi
Dan Smithf3d53312017-06-08 08:22:38 -0400579
580 if is_service_enabled n-cond; then
581 for i in $(seq 1 $NOVA_NUM_CELLS); do
582 local conf
583 local vhost
584 conf=$(conductor_conf $i)
585 vhost="nova_cell${i}"
jiangyikun1a2c86c2017-09-07 17:56:13 +0800586 # clean old conductor conf
587 rm -f $conf
Dan Smithf3d53312017-06-08 08:22:38 -0400588 iniset $conf database connection `database_connection_url nova_cell${i}`
589 iniset $conf conductor workers "$API_WORKERS"
590 iniset $conf DEFAULT debug "$ENABLE_DEBUG_LOG_LEVEL"
Sean Dagueafc14c82017-07-27 07:09:48 -0400591 # if we have a singleconductor, we don't have per host message queues.
592 if [[ "${CELLSV2_SETUP}" == "singleconductor" ]]; then
593 iniset_rpc_backend nova $conf DEFAULT
594 else
595 rpc_backend_add_vhost $vhost
596 iniset_rpc_backend nova $conf DEFAULT $vhost
Matt Riedemannf6d566c2017-12-22 11:39:29 -0500597 # When running in superconductor mode, the cell conductor
598 # must be configured to talk to the placement service for
599 # reschedules to work.
600 if is_service_enabled placement placement-client; then
601 configure_placement_nova_compute $conf
602 fi
Sean Dagueafc14c82017-07-27 07:09:48 -0400603 fi
Matt Riedemann9d7e74e2017-08-25 10:17:18 -0400604 # Format logging
605 setup_logging $conf
Dan Smithf3d53312017-06-08 08:22:38 -0400606 done
607 fi
melanie witt12579c32018-05-05 23:55:32 +0000608
609 # Console proxy configuration has to go after conductor configuration
610 # because the per cell config file nova_cellN.conf is cleared out as part
611 # of conductor configuration.
612 if [[ "${CELLSV2_SETUP}" == "singleconductor" ]]; then
613 configure_console_proxies
614 else
615 for i in $(seq 1 $NOVA_NUM_CELLS); do
616 local conf
melanie wittd5a68a62019-04-02 22:52:23 +0000617 local offset
melanie witt12579c32018-05-05 23:55:32 +0000618 conf=$(conductor_conf $i)
melanie wittd5a68a62019-04-02 22:52:23 +0000619 offset=$((i - 1))
620 configure_console_proxies $conf $offset
melanie witt12579c32018-05-05 23:55:32 +0000621 done
622 fi
623}
624
Chris Dent16a10d72019-01-14 17:16:01 +0000625# Configure access to placement from a nova service, usually
626# compute, but sometimes conductor.
627function configure_placement_nova_compute {
628 # Use the provided config file path or default to $NOVA_CONF.
629 local conf=${1:-$NOVA_CONF}
630 iniset $conf placement auth_type "password"
631 iniset $conf placement auth_url "$KEYSTONE_SERVICE_URI"
632 iniset $conf placement username placement
633 iniset $conf placement password "$SERVICE_PASSWORD"
634 iniset $conf placement user_domain_name "$SERVICE_DOMAIN_NAME"
635 iniset $conf placement project_name "$SERVICE_TENANT_NAME"
636 iniset $conf placement project_domain_name "$SERVICE_DOMAIN_NAME"
637 iniset $conf placement region_name "$REGION_NAME"
638}
639
Matt Riedemann594885c2019-09-27 16:45:09 -0400640# Configure access to cinder.
641function configure_cinder_access {
642 iniset $NOVA_CONF cinder os_region_name "$REGION_NAME"
643 iniset $NOVA_CONF cinder auth_type "password"
644 iniset $NOVA_CONF cinder auth_url "$KEYSTONE_SERVICE_URI"
645 # NOTE(mriedem): This looks a bit weird but we use the nova user here
646 # since it has the admin role and the cinder user does not. This is
647 # similar to using the nova user in init_nova_service_user_conf. We need
648 # to use a user with the admin role for background tasks in nova to
649 # be able to GET block-storage API resources owned by another project
650 # since cinder has low-level "is_admin" checks in its DB API.
651 iniset $NOVA_CONF cinder username nova
652 iniset $NOVA_CONF cinder password "$SERVICE_PASSWORD"
653 iniset $NOVA_CONF cinder user_domain_name "$SERVICE_DOMAIN_NAME"
654 iniset $NOVA_CONF cinder project_name "$SERVICE_TENANT_NAME"
655 iniset $NOVA_CONF cinder project_domain_name "$SERVICE_DOMAIN_NAME"
656 if is_service_enabled tls-proxy; then
657 CINDER_SERVICE_HOST=${CINDER_SERVICE_HOST:-$SERVICE_HOST}
658 CINDER_SERVICE_PORT=${CINDER_SERVICE_PORT:-8776}
659 iniset $NOVA_CONF cinder cafile $SSL_BUNDLE_FILE
660 fi
661}
662
melanie witt65ad7942018-05-09 17:55:40 +0000663function configure_console_compute {
melanie wittd7d902f2019-05-24 20:09:28 +0000664 # If we are running multiple cells (and thus multiple console proxies) on a
665 # single host, we offset the ports to avoid collisions. We need to
666 # correspondingly configure the console proxy port for nova-compute and we
667 # can use the NOVA_CPU_CELL variable to know which cell we are for
668 # calculating the offset.
669 # Stagger the offset based on the total number of possible console proxies
Stephen Finucane3c6d1052021-03-02 16:35:47 +0000670 # (novnc, spice, serial) so that their ports will not collide if
melanie wittd7d902f2019-05-24 20:09:28 +0000671 # all are enabled.
672 local offset
Stephen Finucane3c6d1052021-03-02 16:35:47 +0000673 offset=$(((NOVA_CPU_CELL - 1) * 3))
melanie wittd7d902f2019-05-24 20:09:28 +0000674
melanie witt0a3288c2019-08-09 15:57:50 +0000675 # Use the host IP instead of the service host because for multi-node, the
676 # service host will be the controller only.
677 local default_proxyclient_addr
678 default_proxyclient_addr=$(iniget $NOVA_CPU_CONF DEFAULT my_ip)
679
melanie witt12579c32018-05-05 23:55:32 +0000680 # All nova-compute workers need to know the vnc configuration options
Stephen Finucane3c6d1052021-03-02 16:35:47 +0000681 # These settings don't hurt anything if n-novnc is disabled
melanie witt12579c32018-05-05 23:55:32 +0000682 if is_service_enabled n-cpu; then
Stephen Finucane8c548692018-05-11 16:12:17 +0530683 if [ "$NOVNC_FROM_PACKAGE" == "True" ]; then
684 # Use the old URL when installing novnc packages.
melanie wittd7d902f2019-05-24 20:09:28 +0000685 NOVNCPROXY_URL=${NOVNCPROXY_URL:-"http://$SERVICE_HOST:$((6080 + offset))/vnc_auto.html"}
Stephen Finucane8c548692018-05-11 16:12:17 +0530686 elif vercmp ${NOVNC_BRANCH} "<" "1.0.0"; then
melanie wittd7d902f2019-05-24 20:09:28 +0000687 # Use the old URL when installing older novnc source.
688 NOVNCPROXY_URL=${NOVNCPROXY_URL:-"http://$SERVICE_HOST:$((6080 + offset))/vnc_auto.html"}
Stephen Finucane8c548692018-05-11 16:12:17 +0530689 else
690 # Use the new URL when building >=v1.0.0 from source.
melanie wittd7d902f2019-05-24 20:09:28 +0000691 NOVNCPROXY_URL=${NOVNCPROXY_URL:-"http://$SERVICE_HOST:$((6080 + offset))/vnc_lite.html"}
Stephen Finucane8c548692018-05-11 16:12:17 +0530692 fi
melanie witt65ad7942018-05-09 17:55:40 +0000693 iniset $NOVA_CPU_CONF vnc novncproxy_base_url "$NOVNCPROXY_URL"
Stephen Finucane3c6d1052021-03-02 16:35:47 +0000694 SPICEHTML5PROXY_URL=${SPICEHTML5PROXY_URL:-"http://$SERVICE_HOST:$((6081 + offset))/spice_auto.html"}
melanie witt65ad7942018-05-09 17:55:40 +0000695 iniset $NOVA_CPU_CONF spice html5proxy_base_url "$SPICEHTML5PROXY_URL"
melanie witt12579c32018-05-05 23:55:32 +0000696 fi
697
Stephen Finucane3c6d1052021-03-02 16:35:47 +0000698 if is_service_enabled n-novnc || [ "$NOVA_VNC_ENABLED" != False ]; then
melanie witt12579c32018-05-05 23:55:32 +0000699 # Address on which instance vncservers will listen on compute hosts.
700 # For multi-host, this should be the management ip of the compute host.
melanie witt0a3288c2019-08-09 15:57:50 +0000701 VNCSERVER_LISTEN=${VNCSERVER_LISTEN:-$NOVA_SERVICE_LISTEN_ADDRESS}
702 VNCSERVER_PROXYCLIENT_ADDRESS=${VNCSERVER_PROXYCLIENT_ADDRESS:-$default_proxyclient_addr}
melanie witt65ad7942018-05-09 17:55:40 +0000703 iniset $NOVA_CPU_CONF vnc server_listen "$VNCSERVER_LISTEN"
704 iniset $NOVA_CPU_CONF vnc server_proxyclient_address "$VNCSERVER_PROXYCLIENT_ADDRESS"
705 else
706 iniset $NOVA_CPU_CONF vnc enabled false
707 fi
708
709 if is_service_enabled n-spice; then
710 # Address on which instance spiceservers will listen on compute hosts.
711 # For multi-host, this should be the management ip of the compute host.
melanie witt0a3288c2019-08-09 15:57:50 +0000712 SPICESERVER_PROXYCLIENT_ADDRESS=${SPICESERVER_PROXYCLIENT_ADDRESS:-$default_proxyclient_addr}
713 SPICESERVER_LISTEN=${SPICESERVER_LISTEN:-$NOVA_SERVICE_LISTEN_ADDRESS}
melanie witt65ad7942018-05-09 17:55:40 +0000714 iniset $NOVA_CPU_CONF spice enabled true
715 iniset $NOVA_CPU_CONF spice server_listen "$SPICESERVER_LISTEN"
716 iniset $NOVA_CPU_CONF spice server_proxyclient_address "$SPICESERVER_PROXYCLIENT_ADDRESS"
717 fi
718
719 if is_service_enabled n-sproxy; then
720 iniset $NOVA_CPU_CONF serial_console enabled True
Stephen Finucane3c6d1052021-03-02 16:35:47 +0000721 iniset $NOVA_CPU_CONF serial_console base_url "ws://$SERVICE_HOST:$((6082 + offset))/"
melanie witt65ad7942018-05-09 17:55:40 +0000722 fi
723}
724
725function configure_console_proxies {
726 # Use the provided config file path or default to $NOVA_CONF.
727 local conf=${1:-$NOVA_CONF}
melanie wittd5a68a62019-04-02 22:52:23 +0000728 local offset=${2:-0}
729 # Stagger the offset based on the total number of possible console proxies
Stephen Finucane3c6d1052021-03-02 16:35:47 +0000730 # (novnc, spice, serial) so that their ports will not collide if
melanie wittd5a68a62019-04-02 22:52:23 +0000731 # all are enabled.
Stephen Finucane3c6d1052021-03-02 16:35:47 +0000732 offset=$((offset * 3))
melanie witt65ad7942018-05-09 17:55:40 +0000733
Stephen Finucane3c6d1052021-03-02 16:35:47 +0000734 if is_service_enabled n-novnc || [ "$NOVA_VNC_ENABLED" != False ]; then
melanie witt12579c32018-05-05 23:55:32 +0000735 iniset $conf vnc novncproxy_host "$NOVA_SERVICE_LISTEN_ADDRESS"
melanie wittd5a68a62019-04-02 22:52:23 +0000736 iniset $conf vnc novncproxy_port $((6080 + offset))
melanie witt12579c32018-05-05 23:55:32 +0000737
738 if is_nova_console_proxy_compute_tls_enabled ; then
739 iniset $conf vnc auth_schemes "vencrypt"
740 iniset $conf vnc vencrypt_client_key "/etc/pki/nova-novnc/client-key.pem"
741 iniset $conf vnc vencrypt_client_cert "/etc/pki/nova-novnc/client-cert.pem"
742 iniset $conf vnc vencrypt_ca_certs "/etc/pki/nova-novnc/ca-cert.pem"
743
744 sudo mkdir -p /etc/pki/nova-novnc
745 deploy_int_CA /etc/pki/nova-novnc/ca-cert.pem
746 deploy_int_cert /etc/pki/nova-novnc/client-cert.pem /etc/pki/nova-novnc/client-key.pem
melanie witte2853bf2019-03-13 13:16:51 +0000747 # OpenSSL 1.1.0 generates the key file with permissions: 600, by
748 # default, and the deploy_int* methods use 'sudo cp' to copy the
749 # files, making them owned by root:root.
750 # Change ownership of everything under /etc/pki/nova-novnc to
751 # $STACK_USER:$(id -g ${STACK_USER}) so that $STACK_USER can read
752 # the key file.
753 sudo chown -R $STACK_USER:$(id -g ${STACK_USER}) /etc/pki/nova-novnc
754 # This is needed to enable TLS in the proxy itself, example log:
755 # WebSocket server settings:
756 # - Listen on 0.0.0.0:6080
757 # - Flash security policy server
758 # - Web server (no directory listings). Web root: /usr/share/novnc
759 # - SSL/TLS support
760 # - proxying from 0.0.0.0:6080 to None:None
761 iniset $conf DEFAULT key "/etc/pki/nova-novnc/client-key.pem"
762 iniset $conf DEFAULT cert "/etc/pki/nova-novnc/client-cert.pem"
melanie witt12579c32018-05-05 23:55:32 +0000763 fi
melanie witt12579c32018-05-05 23:55:32 +0000764 fi
765
766 if is_service_enabled n-spice; then
melanie witt12579c32018-05-05 23:55:32 +0000767 iniset $conf spice html5proxy_host "$NOVA_SERVICE_LISTEN_ADDRESS"
Stephen Finucane3c6d1052021-03-02 16:35:47 +0000768 iniset $conf spice html5proxy_port $((6081 + offset))
melanie witt12579c32018-05-05 23:55:32 +0000769 fi
770
771 if is_service_enabled n-sproxy; then
772 iniset $conf serial_console serialproxy_host "$NOVA_SERVICE_LISTEN_ADDRESS"
Stephen Finucane3c6d1052021-03-02 16:35:47 +0000773 iniset $conf serial_console serialproxy_port $((6082 + offset))
melanie witt12579c32018-05-05 23:55:32 +0000774 fi
Pushkar Umaranikar14e16e42016-12-09 20:20:42 +0000775}
776
melanie witt099a0482021-05-06 00:09:33 +0000777function configure_nova_unified_limits {
melanie witt2c961802022-03-03 23:54:49 +0000778 # Registered limit resources in keystone are system-specific resources.
779 # Make sure we use a system-scoped token to interact with this API.
780
781 # Default limits here mirror the legacy config-based default values.
melanie witt099a0482021-05-06 00:09:33 +0000782 # Note: disk quota is new in nova as of unified limits.
melanie witt2c961802022-03-03 23:54:49 +0000783 openstack --os-cloud devstack-system-admin registered limit create \
784 --service nova --default-limit 10 --region $REGION_NAME servers
785 openstack --os-cloud devstack-system-admin registered limit create \
786 --service nova --default-limit 20 --region $REGION_NAME class:VCPU
787 openstack --os-cloud devstack-system-admin registered limit create \
788 --service nova --default-limit $((50 * 1024)) --region $REGION_NAME class:MEMORY_MB
789 openstack --os-cloud devstack-system-admin registered limit create \
790 --service nova --default-limit 20 --region $REGION_NAME class:DISK_GB
791 openstack --os-cloud devstack-system-admin registered limit create \
792 --service nova --default-limit 128 --region $REGION_NAME server_metadata_items
793 openstack --os-cloud devstack-system-admin registered limit create \
794 --service nova --default-limit 5 --region $REGION_NAME server_injected_files
795 openstack --os-cloud devstack-system-admin registered limit create \
796 --service nova --default-limit 10240 --region $REGION_NAME server_injected_file_content_bytes
797 openstack --os-cloud devstack-system-admin registered limit create \
798 --service nova --default-limit 255 --region $REGION_NAME server_injected_file_path_bytes
799 openstack --os-cloud devstack-system-admin registered limit create \
800 --service nova --default-limit 100 --region $REGION_NAME server_key_pairs
801 openstack --os-cloud devstack-system-admin registered limit create \
802 --service nova --default-limit 10 --region $REGION_NAME server_groups
803 openstack --os-cloud devstack-system-admin registered limit create \
804 --service nova --default-limit 10 --region $REGION_NAME server_group_members
melanie witt099a0482021-05-06 00:09:33 +0000805
806 # Tell nova to use these limits
807 iniset $NOVA_CONF quota driver "nova.quota.UnifiedLimitsDriver"
808
809 # Configure oslo_limit so it can talk to keystone
810 iniset $NOVA_CONF oslo_limit user_domain_name $SERVICE_DOMAIN_NAME
811 iniset $NOVA_CONF oslo_limit password $SERVICE_PASSWORD
812 iniset $NOVA_CONF oslo_limit username nova
813 iniset $NOVA_CONF oslo_limit auth_type password
814 iniset $NOVA_CONF oslo_limit auth_url $KEYSTONE_SERVICE_URI
melanie witt2c961802022-03-03 23:54:49 +0000815 iniset $NOVA_CONF oslo_limit system_scope all
melanie witt099a0482021-05-06 00:09:33 +0000816 iniset $NOVA_CONF oslo_limit endpoint_id \
817 $(openstack endpoint list --service nova -f value -c ID)
818
819 # Allow the nova service user to read quotas
melanie witt2c961802022-03-03 23:54:49 +0000820 openstack --os-cloud devstack-system-admin role add --user nova \
821 --user-domain $SERVICE_DOMAIN_NAME --system all reader
melanie witt099a0482021-05-06 00:09:33 +0000822}
823
Pushkar Umaranikar14e16e42016-12-09 20:20:42 +0000824function init_nova_service_user_conf {
825 iniset $NOVA_CONF service_user send_service_user_token True
826 iniset $NOVA_CONF service_user auth_type password
Brant Knudsonc2c89e42017-02-23 20:15:47 -0600827 iniset $NOVA_CONF service_user auth_url "$KEYSTONE_SERVICE_URI"
Pushkar Umaranikar14e16e42016-12-09 20:20:42 +0000828 iniset $NOVA_CONF service_user username nova
829 iniset $NOVA_CONF service_user password "$SERVICE_PASSWORD"
830 iniset $NOVA_CONF service_user user_domain_name "$SERVICE_DOMAIN_NAME"
831 iniset $NOVA_CONF service_user project_name "$SERVICE_PROJECT_NAME"
832 iniset $NOVA_CONF service_user project_domain_name "$SERVICE_DOMAIN_NAME"
833 iniset $NOVA_CONF service_user auth_strategy keystone
Dean Troyerda7b8092012-10-08 18:12:14 -0500834}
Dean Troyerbf67c192012-09-21 15:09:37 -0500835
Dan Smithf3d53312017-06-08 08:22:38 -0400836function conductor_conf {
837 local cell="$1"
838 echo "${NOVA_CONF_DIR}/nova_cell${cell}.conf"
839}
840
Dean Troyerf03bafe2013-02-12 10:58:28 -0600841# create_nova_keys_dir() - Part of the init_nova() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100842function create_nova_keys_dir {
Dean Troyerf03bafe2013-02-12 10:58:28 -0600843 # Create keys dir
Dean Troyer8421c2b2015-03-16 13:52:19 -0500844 sudo install -d -o $STACK_USER ${NOVA_STATE_PATH} ${NOVA_STATE_PATH}/keys
Dean Troyerf03bafe2013-02-12 10:58:28 -0600845}
846
Dan Smith30d9bf92021-01-19 12:10:52 -0800847function init_nova_db {
848 local dbname="$1"
849 local conffile="$2"
850 recreate_database $dbname
851 $NOVA_BIN_DIR/nova-manage --config-file $conffile db sync --local_cell
852}
853
Dean Troyerda7b8092012-10-08 18:12:14 -0500854# init_nova() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100855function init_nova {
Dean Troyerf03bafe2013-02-12 10:58:28 -0600856 # All nova components talk to a central database.
857 # Only do this step once on the API node for an entire cluster.
Bob Melanderc439b5d2012-12-19 14:49:34 +0100858 if is_service_enabled $DATABASE_BACKENDS && is_service_enabled n-api; then
Dan Smith30d9bf92021-01-19 12:10:52 -0800859 # (Re)create nova databases
Dan Smith48b76332021-02-16 14:14:23 -0800860 if [[ "$CELLSV2_SETUP" == "singleconductor" ]]; then
861 # If we are doing singleconductor mode, we have some strange
862 # interdependencies. in that the main config refers to cell1
863 # instead of cell0. In that case, just make sure the cell0 database
864 # is created before we need it below, but don't db_sync it until
865 # after the cellN databases are there.
866 recreate_database nova_cell0
867 else
868 async_run nova-cell-0 init_nova_db nova_cell0 $NOVA_CONF
869 fi
870
Dan Smith30d9bf92021-01-19 12:10:52 -0800871 for i in $(seq 1 $NOVA_NUM_CELLS); do
872 async_run nova-cell-$i init_nova_db nova_cell${i} $(conductor_conf $i)
873 done
874
Roman Podoliakaf575aef2016-10-11 13:15:55 +0300875 recreate_database $NOVA_API_DB
876 $NOVA_BIN_DIR/nova-manage --config-file $NOVA_CONF api_db sync
877
Matt Riedemannac5fdb42017-01-31 15:20:18 -0500878 # map_cell0 will create the cell mapping record in the nova_api DB so
Dan Smith30d9bf92021-01-19 12:10:52 -0800879 # this needs to come after the api_db sync happens.
Paul Belangera62ede72018-03-14 11:58:56 -0400880 $NOVA_BIN_DIR/nova-manage cell_v2 map_cell0 --database_connection `database_connection_url nova_cell0`
Matt Riedemannac5fdb42017-01-31 15:20:18 -0500881
Dan Smith30d9bf92021-01-19 12:10:52 -0800882 # Wait for DBs to finish from above
883 for i in $(seq 0 $NOVA_NUM_CELLS); do
884 async_wait nova-cell-$i
Dan Smithf3d53312017-06-08 08:22:38 -0400885 done
886
Dan Smith48b76332021-02-16 14:14:23 -0800887 if [[ "$CELLSV2_SETUP" == "singleconductor" ]]; then
888 # We didn't db sync cell0 above, so run it now
889 $NOVA_BIN_DIR/nova-manage --config-file $NOVA_CONF db sync
890 fi
891
Dan Smithbb49d352016-03-28 11:03:35 -0700892 # Run online migrations on the new databases
893 # Needed for flavor conversion
Einst Crazy4f55c2d2016-05-04 08:14:01 +0000894 $NOVA_BIN_DIR/nova-manage --config-file $NOVA_CONF db online_data_migrations
Matt Riedemannf15224c2017-03-02 12:45:47 -0500895
896 # create the cell1 cell for the main nova db where the hosts live
Dan Smithf3d53312017-06-08 08:22:38 -0400897 for i in $(seq 1 $NOVA_NUM_CELLS); do
Paul Belangera62ede72018-03-14 11:58:56 -0400898 $NOVA_BIN_DIR/nova-manage --config-file $NOVA_CONF --config-file $(conductor_conf $i) cell_v2 create_cell --name "cell$i"
Dan Smithf3d53312017-06-08 08:22:38 -0400899 done
Dean Troyerbf67c192012-09-21 15:09:37 -0500900 fi
901
Dean Troyerf03bafe2013-02-12 10:58:28 -0600902 create_nova_keys_dir
Maru Newbyc070a3d2015-01-27 17:44:44 +0000903
904 if [[ "$NOVA_BACKEND" == "LVM" ]]; then
905 init_default_lvm_volume_group
906 fi
Dean Troyerbf67c192012-09-21 15:09:37 -0500907}
908
909# install_novaclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100910function install_novaclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500911 if use_library_from_git "python-novaclient"; then
912 git_clone_by_name "python-novaclient"
913 setup_dev_lib "python-novaclient"
914 sudo install -D -m 0644 -o $STACK_USER {${GITDIR["python-novaclient"]}/tools/,/etc/bash_completion.d/}nova.bash_completion
Sean Dague5cb19062014-11-01 01:37:45 +0100915 fi
Dean Troyerbf67c192012-09-21 15:09:37 -0500916}
917
918# install_nova() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100919function install_nova {
Sergey Belous1258da62016-03-21 12:32:06 +0300920
921 # Install os-vif
922 if use_library_from_git "os-vif"; then
923 git_clone_by_name "os-vif"
924 setup_dev_lib "os-vif"
925 fi
926
Dean Troyer8c032d12013-09-23 13:53:13 -0500927 if is_service_enabled n-cpu && [[ -r $NOVA_PLUGINS/hypervisor-$VIRT_DRIVER ]]; then
928 install_nova_hypervisor
Dean Troyerbf67c192012-09-21 15:09:37 -0500929 fi
930
Attila Fazekas5a35e732013-10-29 08:23:43 +0100931 if is_service_enabled n-novnc; then
932 # a websockets/html5 or flash powered VNC console for vm instances
Sean Dague53753292014-12-04 19:38:15 -0500933 NOVNC_FROM_PACKAGE=$(trueorfalse False NOVNC_FROM_PACKAGE)
Ben Nemecadd4ca32013-11-08 17:22:51 +0000934 if [ "$NOVNC_FROM_PACKAGE" = "True" ]; then
Clark Boylan97b2a512022-11-09 11:58:37 -0800935 # Installing novnc on Debian bullseye breaks the global pip
936 # install. This happens because novnc pulls in distro cryptography
937 # which will be prefered by distro pip, but if anything has
938 # installed pyOpenSSL from pypi (keystone) that is not compatible
939 # with distro cryptography. Fix this by installing
940 # python3-openssl (pyOpenSSL) from the distro which pip will prefer
941 # on Debian. Ubuntu has inverse problems so we only do this for
942 # Debian.
943 local novnc_packages
944 novnc_packages="novnc"
945 GetOSVersion
946 if [[ "$os_VENDOR" = "Debian" ]] ; then
947 novnc_packages="$novnc_packages python3-openssl"
948 fi
949
Attila Fazekas5a35e732013-10-29 08:23:43 +0100950 NOVNC_WEB_DIR=/usr/share/novnc
Clark Boylan97b2a512022-11-09 11:58:37 -0800951 install_package $novnc_packages
Attila Fazekas5a35e732013-10-29 08:23:43 +0100952 else
Lee Yarwood31334f92021-11-04 18:30:29 +0000953 NOVNC_WEB_DIR=$DEST/novnc
Attila Fazekas5a35e732013-10-29 08:23:43 +0100954 git_clone $NOVNC_REPO $NOVNC_WEB_DIR $NOVNC_BRANCH
955 fi
956 fi
957
958 if is_service_enabled n-spice; then
959 # a websockets/html5 or flash powered SPICE console for vm instances
Sean Dague53753292014-12-04 19:38:15 -0500960 SPICE_FROM_PACKAGE=$(trueorfalse True SPICE_FROM_PACKAGE)
Ben Nemecadd4ca32013-11-08 17:22:51 +0000961 if [ "$SPICE_FROM_PACKAGE" = "True" ]; then
Attila Fazekas5a35e732013-10-29 08:23:43 +0100962 SPICE_WEB_DIR=/usr/share/spice-html5
963 install_package spice-html5
964 else
965 SPICE_WEB_DIR=$DEST/spice-html5
966 git_clone $SPICE_REPO $SPICE_WEB_DIR $SPICE_BRANCH
967 fi
968 fi
969
Dean Troyerbf67c192012-09-21 15:09:37 -0500970 git_clone $NOVA_REPO $NOVA_DIR $NOVA_BRANCH
Dean Troyer253a1a32013-04-01 18:23:22 -0500971 setup_develop $NOVA_DIR
Attila Fazekasfac533e2013-08-14 16:04:01 +0200972 sudo install -D -m 0644 -o $STACK_USER {$NOVA_DIR/tools/,/etc/bash_completion.d/}nova-manage.bash_completion
Dean Troyerbf67c192012-09-21 15:09:37 -0500973}
974
Dean Troyer3a3a2ba2012-12-11 15:26:24 -0600975# start_nova_api() - Start the API process ahead of other things
Ian Wienandaee18c72014-02-21 15:35:08 +1100976function start_nova_api {
Dean Troyer3a3a2ba2012-12-11 15:26:24 -0600977 # Get right service port for testing
978 local service_port=$NOVA_SERVICE_PORT
Rob Crittenden18d47782014-03-19 17:47:42 -0400979 local service_protocol=$NOVA_SERVICE_PROTOCOL
Chris Dentb90bb1a2017-04-18 16:30:14 +0000980 local nova_url
Dean Troyer3a3a2ba2012-12-11 15:26:24 -0600981 if is_service_enabled tls-proxy; then
982 service_port=$NOVA_SERVICE_PORT_INT
Rob Crittenden18d47782014-03-19 17:47:42 -0400983 service_protocol="http"
Dean Troyer3a3a2ba2012-12-11 15:26:24 -0600984 fi
985
Dean Troyer4533eee2015-02-17 16:25:38 -0600986 # Hack to set the path for rootwrap
987 local old_path=$PATH
988 export PATH=$NOVA_BIN_DIR:$PATH
989
Chris Dentb90bb1a2017-04-18 16:30:14 +0000990 if [ "$NOVA_USE_MOD_WSGI" == "False" ]; then
Davanum Srinivasd5537c12015-04-30 21:10:48 -0400991 run_process n-api "$NOVA_BIN_DIR/nova-api"
Chris Dentb90bb1a2017-04-18 16:30:14 +0000992 nova_url=$service_protocol://$SERVICE_HOST:$service_port
993 # Start proxy if tsl enabled
994 if is_service_enabled tls-proxy; then
995 start_tls_proxy nova '*' $NOVA_SERVICE_PORT $NOVA_SERVICE_HOST $NOVA_SERVICE_PORT_INT
996 fi
997 else
Ian Wienand312517d2018-06-22 22:23:29 +1000998 run_process "n-api" "$(which uwsgi) --procname-prefix nova-api --ini $NOVA_UWSGI_CONF"
Chris Dentb90bb1a2017-04-18 16:30:14 +0000999 nova_url=$service_protocol://$SERVICE_HOST/compute/v2.1/
Davanum Srinivasd5537c12015-04-30 21:10:48 -04001000 fi
1001
Dean Troyer3a3a2ba2012-12-11 15:26:24 -06001002 echo "Waiting for nova-api to start..."
Chris Dentb90bb1a2017-04-18 16:30:14 +00001003 if ! wait_for_service $SERVICE_TIMEOUT $nova_url; then
Sean Dague101b4242013-10-22 08:47:11 -04001004 die $LINENO "nova-api did not start"
Dean Troyer3a3a2ba2012-12-11 15:26:24 -06001005 fi
1006
Dean Troyer4533eee2015-02-17 16:25:38 -06001007 export PATH=$old_path
Dean Troyer3a3a2ba2012-12-11 15:26:24 -06001008}
1009
Sean Dagueafc14c82017-07-27 07:09:48 -04001010
Dan Smith2e159462013-10-21 13:06:11 -07001011# start_nova_compute() - Start the compute process
Ian Wienandaee18c72014-02-21 15:35:08 +11001012function start_nova_compute {
Dean Troyer4533eee2015-02-17 16:25:38 -06001013 # Hack to set the path for rootwrap
1014 local old_path=$PATH
1015 export PATH=$NOVA_BIN_DIR:$PATH
1016
Stephen Finucane4b8cba72019-05-21 14:17:11 +01001017 local compute_cell_conf=$NOVA_CONF
Kieran Spearfb2a3ae2013-03-11 23:55:49 +00001018
Eric Fried2468cea2019-07-25 13:18:58 -05001019 # Bug #1802143: $NOVA_CPU_CONF is constructed by first copying $NOVA_CONF...
Matt Riedemann82537872019-01-18 10:42:13 -05001020 cp $compute_cell_conf $NOVA_CPU_CONF
Eric Fried2468cea2019-07-25 13:18:58 -05001021 # ...and then adding/overriding anything explicitly set in $NOVA_CPU_CONF
1022 merge_config_file $TOP_DIR/local.conf post-config '$NOVA_CPU_CONF'
Matt Riedemann82537872019-01-18 10:42:13 -05001023
Sean Dague5adfef02017-07-26 11:14:37 -04001024 if [[ "${CELLSV2_SETUP}" == "singleconductor" ]]; then
Dan Smithf3d53312017-06-08 08:22:38 -04001025 # NOTE(danms): Grenade doesn't setup multi-cell rabbit, so
1026 # skip these bits and use the normal config.
Dan Smithf3d53312017-06-08 08:22:38 -04001027 echo "Skipping multi-cell conductor fleet setup"
1028 else
Sean Dague5adfef02017-07-26 11:14:37 -04001029 # "${CELLSV2_SETUP}" is "superconductor"
Dan Smithf3d53312017-06-08 08:22:38 -04001030 # FIXME(danms): Should this be configurable?
1031 iniset $NOVA_CPU_CONF workarounds disable_group_policy_check_upcall True
Matt Riedemannab980ce2017-08-01 16:38:42 -04001032 # Since the nova-compute service cannot reach nova-scheduler over
1033 # RPC, we also disable track_instance_changes.
1034 iniset $NOVA_CPU_CONF filter_scheduler track_instance_changes False
Dan Smithf3d53312017-06-08 08:22:38 -04001035 iniset_rpc_backend nova $NOVA_CPU_CONF DEFAULT "nova_cell${NOVA_CPU_CELL}"
1036 fi
1037
Matt Riedemann82537872019-01-18 10:42:13 -05001038 # Make sure we nuke any database config
1039 inidelete $NOVA_CPU_CONF database connection
1040 inidelete $NOVA_CPU_CONF api_database connection
1041
melanie witt65ad7942018-05-09 17:55:40 +00001042 # Console proxies were configured earlier in create_nova_conf. Now that the
1043 # nova-cpu.conf has been created, configure the console settings required
1044 # by the compute process.
1045 configure_console_compute
1046
Dan Smith58c80b22023-06-27 12:16:32 -07001047 # Set rebuild timeout longer for BFV instances because we likely have
1048 # slower disk than expected. Default is 20s/GB
1049 iniset $NOVA_CPU_CONF DEFAULT reimage_timeout_per_gb 60
1050
Lucas Alvares Gomes6ecfe672020-09-23 11:54:19 +01001051 # Configure the OVSDB connection for os-vif
1052 if [ -n "$OVSDB_SERVER_LOCAL_HOST" ]; then
1053 iniset $NOVA_CPU_CONF os_vif_ovs ovsdb_connection "tcp:$OVSDB_SERVER_LOCAL_HOST:6640"
1054 fi
1055
Lee Yarwood1e86a252021-08-19 14:24:28 +01001056 # Workaround bug #1939108
1057 if [[ "$VIRT_DRIVER" == "libvirt" && "$LIBVIRT_TYPE" == "qemu" ]]; then
1058 iniset $NOVA_CPU_CONF workarounds libvirt_disable_apic True
1059 fi
1060
Bob Ballb1e49bf2013-05-30 16:47:19 +01001061 if [[ "$VIRT_DRIVER" = 'libvirt' ]]; then
1062 # The group **$LIBVIRT_GROUP** is added to the current user in this script.
Dean Troyer3324f192014-09-18 09:26:39 -05001063 # ``sg`` is used in run_process to execute nova-compute as a member of the
Chris Dent2f27a0e2014-09-09 13:46:02 +01001064 # **$LIBVIRT_GROUP** group.
Dan Smithf3d53312017-06-08 08:22:38 -04001065 run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $NOVA_CPU_CONF" $LIBVIRT_GROUP
Lubosz "diltram" Kosnik0ffdfbd2016-08-02 16:35:22 -05001066 elif [[ "$VIRT_DRIVER" = 'lxd' ]]; then
Dan Smithf3d53312017-06-08 08:22:38 -04001067 run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $NOVA_CPU_CONF" $LXD_GROUP
Hongbin Lu53a49d12016-12-23 16:16:50 -06001068 elif [[ "$VIRT_DRIVER" = 'docker' || "$VIRT_DRIVER" = 'zun' ]]; then
Dan Smithf3d53312017-06-08 08:22:38 -04001069 run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $NOVA_CPU_CONF" $DOCKER_GROUP
Joe Gordon2c94ee52013-08-02 02:02:01 +00001070 elif [[ "$VIRT_DRIVER" = 'fake' ]]; then
Dean Troyer0038a1a2014-07-25 15:27:54 -05001071 local i
Sean Dague101b4242013-10-22 08:47:11 -04001072 for i in `seq 1 $NUMBER_FAKE_NOVA_COMPUTE`; do
Chris Dent2f27a0e2014-09-09 13:46:02 +01001073 # Avoid process redirection of fake host configurations by
1074 # creating or modifying real configurations. Each fake
1075 # gets its own configuration and own log file.
1076 local fake_conf="${NOVA_FAKE_CONF}-${i}"
Chris Dentac475bb2018-02-07 18:35:40 +00001077 iniset $fake_conf DEFAULT host "${HOSTNAME}${i}"
Dan Smithf3d53312017-06-08 08:22:38 -04001078 run_process "n-cpu-${i}" "$NOVA_BIN_DIR/nova-compute --config-file $NOVA_CPU_CONF --config-file $fake_conf"
Sean Dague101b4242013-10-22 08:47:11 -04001079 done
Bob Ballb1e49bf2013-05-30 16:47:19 +01001080 else
Dean Troyer2aa2a892013-08-04 19:53:19 -05001081 if is_service_enabled n-cpu && [[ -r $NOVA_PLUGINS/hypervisor-$VIRT_DRIVER ]]; then
1082 start_nova_hypervisor
1083 fi
Dan Smithf3d53312017-06-08 08:22:38 -04001084 run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $NOVA_CPU_CONF"
Bob Ballb1e49bf2013-05-30 16:47:19 +01001085 fi
Dean Troyer4533eee2015-02-17 16:25:38 -06001086
1087 export PATH=$old_path
Dan Smith2e159462013-10-21 13:06:11 -07001088}
1089
Sean Dague0eebeb42017-08-30 14:16:58 -04001090# start_nova() - Start running processes
Ian Wienandaee18c72014-02-21 15:35:08 +11001091function start_nova_rest {
Dean Troyer4533eee2015-02-17 16:25:38 -06001092 # Hack to set the path for rootwrap
1093 local old_path=$PATH
1094 export PATH=$NOVA_BIN_DIR:$PATH
1095
Stephen Finucane4b8cba72019-05-21 14:17:11 +01001096 local compute_cell_conf=$NOVA_CONF
Ihar Hrachyshkab3a210f2016-09-29 13:26:30 +00001097
Chris Dent2f27a0e2014-09-09 13:46:02 +01001098 run_process n-sch "$NOVA_BIN_DIR/nova-scheduler --config-file $compute_cell_conf"
Chris Dentb90bb1a2017-04-18 16:30:14 +00001099 if [ "$NOVA_USE_MOD_WSGI" == "False" ]; then
1100 run_process n-api-meta "$NOVA_BIN_DIR/nova-api-metadata --config-file $compute_cell_conf"
1101 else
Ian Wienand312517d2018-06-22 22:23:29 +10001102 run_process n-api-meta "$(which uwsgi) --procname-prefix nova-api-meta --ini $NOVA_METADATA_UWSGI_CONF"
Chris Dentb90bb1a2017-04-18 16:30:14 +00001103 fi
Chris Behrens86199fc2013-10-23 02:54:53 -07001104
melanie witted2d4912017-07-18 22:29:41 +00001105 export PATH=$old_path
1106}
1107
1108function enable_nova_console_proxies {
1109 for i in $(seq 1 $NOVA_NUM_CELLS); do
Stephen Finucane3c6d1052021-03-02 16:35:47 +00001110 for srv in n-novnc n-spice n-sproxy; do
melanie witted2d4912017-07-18 22:29:41 +00001111 if is_service_enabled $srv; then
1112 enable_service ${srv}-cell${i}
1113 fi
1114 done
1115 done
1116}
1117
1118function start_nova_console_proxies {
1119 # Hack to set the path for rootwrap
1120 local old_path=$PATH
1121 # This is needed to find the nova conf
1122 export PATH=$NOVA_BIN_DIR:$PATH
1123
1124 local api_cell_conf=$NOVA_CONF
1125 # console proxies run globally for singleconductor, else they run per cell
1126 if [[ "${CELLSV2_SETUP}" == "singleconductor" ]]; then
1127 run_process n-novnc "$NOVA_BIN_DIR/nova-novncproxy --config-file $api_cell_conf --web $NOVNC_WEB_DIR"
melanie witted2d4912017-07-18 22:29:41 +00001128 run_process n-spice "$NOVA_BIN_DIR/nova-spicehtml5proxy --config-file $api_cell_conf --web $SPICE_WEB_DIR"
1129 run_process n-sproxy "$NOVA_BIN_DIR/nova-serialproxy --config-file $api_cell_conf"
1130 else
1131 enable_nova_console_proxies
1132 for i in $(seq 1 $NOVA_NUM_CELLS); do
1133 local conf
1134 conf=$(conductor_conf $i)
1135 run_process n-novnc-cell${i} "$NOVA_BIN_DIR/nova-novncproxy --config-file $conf --web $NOVNC_WEB_DIR"
melanie witted2d4912017-07-18 22:29:41 +00001136 run_process n-spice-cell${i} "$NOVA_BIN_DIR/nova-spicehtml5proxy --config-file $conf --web $SPICE_WEB_DIR"
1137 run_process n-sproxy-cell${i} "$NOVA_BIN_DIR/nova-serialproxy --config-file $conf"
1138 done
1139 fi
Dean Troyer1c6c1122013-03-27 17:40:53 -05001140
Dean Troyer4533eee2015-02-17 16:25:38 -06001141 export PATH=$old_path
Dean Troyerbf67c192012-09-21 15:09:37 -05001142}
1143
Dan Smithf3d53312017-06-08 08:22:38 -04001144function enable_nova_fleet {
1145 if is_service_enabled n-cond; then
1146 enable_service n-super-cond
1147 for i in $(seq 1 $NOVA_NUM_CELLS); do
1148 enable_service n-cond-cell${i}
1149 done
1150 fi
1151}
1152
1153function start_nova_conductor {
Sean Dagueafc14c82017-07-27 07:09:48 -04001154 if [[ "${CELLSV2_SETUP}" == "singleconductor" ]]; then
Dan Smithf3d53312017-06-08 08:22:38 -04001155 echo "Starting nova-conductor in a cellsv1-compatible way"
Sean Dagueafc14c82017-07-27 07:09:48 -04001156 run_process n-cond "$NOVA_BIN_DIR/nova-conductor --config-file $NOVA_COND_CONF"
Dan Smithf3d53312017-06-08 08:22:38 -04001157 return
1158 fi
1159
1160 enable_nova_fleet
1161 if is_service_enabled n-super-cond; then
Sean Dagueafc14c82017-07-27 07:09:48 -04001162 run_process n-super-cond "$NOVA_BIN_DIR/nova-conductor --config-file $NOVA_COND_CONF"
Dan Smithf3d53312017-06-08 08:22:38 -04001163 fi
1164 for i in $(seq 1 $NOVA_NUM_CELLS); do
1165 if is_service_enabled n-cond-cell${i}; then
1166 local conf
1167 conf=$(conductor_conf $i)
1168 run_process n-cond-cell${i} "$NOVA_BIN_DIR/nova-conductor --config-file $conf"
1169 fi
1170 done
1171}
1172
Sean Daguec2fe9162017-07-28 11:29:18 +00001173function is_nova_ready {
1174 # NOTE(sdague): with cells v2 all the compute services must be up
1175 # and checked into the database before discover_hosts is run. This
1176 # happens in all in one installs by accident, because > 30 seconds
1177 # happen between here and the script ending. However, in multinode
1178 # tests this can very often not be the case. So ensure that the
1179 # compute is up before we move on.
Jens Harbott730ce452018-02-23 13:56:48 +00001180 wait_for_compute $NOVA_READY_TIMEOUT
Sean Daguec2fe9162017-07-28 11:29:18 +00001181}
1182
Ian Wienandaee18c72014-02-21 15:35:08 +11001183function start_nova {
Dan Smith2e159462013-10-21 13:06:11 -07001184 start_nova_rest
melanie witted2d4912017-07-18 22:29:41 +00001185 start_nova_console_proxies
Dan Smithf3d53312017-06-08 08:22:38 -04001186 start_nova_conductor
Li Ma26ac3d72014-12-21 23:41:07 -08001187 start_nova_compute
Sean Dagueafc14c82017-07-27 07:09:48 -04001188 if is_service_enabled n-api; then
1189 # dump the cell mapping to ensure life is good
1190 echo "Dumping cells_v2 mapping"
Paul Belangera62ede72018-03-14 11:58:56 -04001191 $NOVA_BIN_DIR/nova-manage cell_v2 list_cells --verbose
Sean Dagueafc14c82017-07-27 07:09:48 -04001192 fi
Dan Smith2e159462013-10-21 13:06:11 -07001193}
1194
Joe Gordon767b5a42014-03-12 10:33:15 -07001195function stop_nova_compute {
Adam Gandelmand29ca352014-10-06 14:33:59 -07001196 if [ "$VIRT_DRIVER" == "fake" ]; then
1197 local i
1198 for i in `seq 1 $NUMBER_FAKE_NOVA_COMPUTE`; do
1199 stop_process n-cpu-${i}
1200 done
1201 else
1202 stop_process n-cpu
1203 fi
Joe Gordon767b5a42014-03-12 10:33:15 -07001204 if is_service_enabled n-cpu && [[ -r $NOVA_PLUGINS/hypervisor-$VIRT_DRIVER ]]; then
1205 stop_nova_hypervisor
1206 fi
1207}
1208
1209function stop_nova_rest {
Chris Dentb90bb1a2017-04-18 16:30:14 +00001210 # Kill the non-compute nova processes
Stephen Finucane4b8cba72019-05-21 14:17:11 +01001211 for serv in n-api n-api-meta n-sch; do
Chris Dent2f27a0e2014-09-09 13:46:02 +01001212 stop_process $serv
Dean Troyerbf67c192012-09-21 15:09:37 -05001213 done
Joe Gordon767b5a42014-03-12 10:33:15 -07001214}
1215
melanie witted2d4912017-07-18 22:29:41 +00001216function stop_nova_console_proxies {
1217 if [[ "${CELLSV2_SETUP}" == "singleconductor" ]]; then
Stephen Finucane3c6d1052021-03-02 16:35:47 +00001218 for srv in n-novnc n-spice n-sproxy; do
melanie witted2d4912017-07-18 22:29:41 +00001219 stop_process $srv
1220 done
1221 else
1222 enable_nova_console_proxies
1223 for i in $(seq 1 $NOVA_NUM_CELLS); do
Stephen Finucane3c6d1052021-03-02 16:35:47 +00001224 for srv in n-novnc n-spice n-sproxy; do
melanie witted2d4912017-07-18 22:29:41 +00001225 stop_process ${srv}-cell${i}
1226 done
1227 done
1228 fi
1229}
1230
Dan Smithf3d53312017-06-08 08:22:38 -04001231function stop_nova_conductor {
Davanum Srinivas98c95f42017-08-16 09:10:04 -04001232 if [[ "${CELLSV2_SETUP}" == "singleconductor" ]]; then
1233 stop_process n-cond
1234 return
1235 fi
1236
Dan Smithf3d53312017-06-08 08:22:38 -04001237 enable_nova_fleet
1238 for srv in n-super-cond $(seq -f n-cond-cell%0.f 1 $NOVA_NUM_CELLS); do
1239 if is_service_enabled $srv; then
1240 stop_process $srv
1241 fi
1242 done
1243}
1244
Sean Dague0eebeb42017-08-30 14:16:58 -04001245# stop_nova() - Stop running processes
Joe Gordon767b5a42014-03-12 10:33:15 -07001246function stop_nova {
1247 stop_nova_rest
melanie witted2d4912017-07-18 22:29:41 +00001248 stop_nova_console_proxies
Dan Smithf3d53312017-06-08 08:22:38 -04001249 stop_nova_conductor
Joe Gordon767b5a42014-03-12 10:33:15 -07001250 stop_nova_compute
Dean Troyerbf67c192012-09-21 15:09:37 -05001251}
1252
Dan Smith4b205db2016-04-04 10:37:11 -07001253# create_instance_types(): Create default flavors
1254function create_flavors {
Dan Smithd3d21392016-04-06 14:06:00 -07001255 if is_service_enabled n-api; then
Victor Ryzhenkin878d7d82016-04-27 15:15:52 +03001256 if ! openstack --os-region-name="$REGION_NAME" flavor list | grep -q ds512M; then
Dan Smithd3d21392016-04-06 14:06:00 -07001257 # Note that danms hates these flavors and apologizes for sdague
Clark Boylan7ddbece2019-12-03 14:35:03 -08001258 openstack --os-region-name="$REGION_NAME" flavor create --id c1 --ram 256 --disk 1 --vcpus 1 --property hw_rng:allowed=True cirros256
1259 openstack --os-region-name="$REGION_NAME" flavor create --id d1 --ram 512 --disk 5 --vcpus 1 --property hw_rng:allowed=True ds512M
1260 openstack --os-region-name="$REGION_NAME" flavor create --id d2 --ram 1024 --disk 10 --vcpus 1 --property hw_rng:allowed=True ds1G
1261 openstack --os-region-name="$REGION_NAME" flavor create --id d3 --ram 2048 --disk 10 --vcpus 2 --property hw_rng:allowed=True ds2G
1262 openstack --os-region-name="$REGION_NAME" flavor create --id d4 --ram 4096 --disk 20 --vcpus 4 --property hw_rng:allowed=True ds4G
Dan Smithd3d21392016-04-06 14:06:00 -07001263 fi
Dan Smith4b205db2016-04-04 10:37:11 -07001264
Victor Ryzhenkin878d7d82016-04-27 15:15:52 +03001265 if ! openstack --os-region-name="$REGION_NAME" flavor list | grep -q m1.tiny; then
Clark Boylan7ddbece2019-12-03 14:35:03 -08001266 openstack --os-region-name="$REGION_NAME" flavor create --id 1 --ram 512 --disk 1 --vcpus 1 --property hw_rng:allowed=True m1.tiny
1267 openstack --os-region-name="$REGION_NAME" flavor create --id 2 --ram 2048 --disk 20 --vcpus 1 --property hw_rng:allowed=True m1.small
1268 openstack --os-region-name="$REGION_NAME" flavor create --id 3 --ram 4096 --disk 40 --vcpus 2 --property hw_rng:allowed=True m1.medium
1269 openstack --os-region-name="$REGION_NAME" flavor create --id 4 --ram 8192 --disk 80 --vcpus 4 --property hw_rng:allowed=True m1.large
1270 openstack --os-region-name="$REGION_NAME" flavor create --id 5 --ram 16384 --disk 160 --vcpus 8 --property hw_rng:allowed=True m1.xlarge
Dan Smithd3d21392016-04-06 14:06:00 -07001271 fi
Dan Smith4b205db2016-04-04 10:37:11 -07001272 fi
1273}
Dean Troyercc6b4432013-04-08 15:38:03 -05001274
Dean Troyerbf67c192012-09-21 15:09:37 -05001275# Restore xtrace
Ian Wienand523f4882015-10-13 11:03:03 +11001276$_XTRACE_LIB_NOVA
Sean Dague584d90e2013-03-29 14:34:53 -04001277
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01001278# Tell emacs to use shell-script-mode
1279## Local variables:
1280## mode: shell-script
1281## End: