blob: ebc3db5eebf5ea41774b37fd11c1ba6335d8382d [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
10# - ``SERVICE_{TENANT_NAME|PASSWORD}`` must be defined
11# - ``LIBVIRT_TYPE`` must be defined
12# - ``INSTANCE_NAME_PREFIX``, ``VOLUME_NAME_PREFIX`` must be defined
13# - ``KEYSTONE_TOKEN_FORMAT`` must be defined
Dean Troyerbf67c192012-09-21 15:09:37 -050014
15# ``stack.sh`` calls the entry points in this order:
16#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010017# - install_nova
18# - configure_nova
19# - create_nova_conf
20# - init_nova
21# - start_nova
22# - stop_nova
23# - cleanup_nova
Dean Troyerbf67c192012-09-21 15:09:37 -050024
25# Save trace setting
26XTRACE=$(set +o | grep xtrace)
27set +o xtrace
28
29
30# Defaults
31# --------
32
33# Set up default directories
Sean Daguee08ab102014-11-13 17:09:28 -050034GITDIR["python-novaclient"]=$DEST/python-novaclient
Sean Dague5cb19062014-11-01 01:37:45 +010035
36
Dean Troyerbf67c192012-09-21 15:09:37 -050037NOVA_DIR=$DEST/nova
Dean Troyerbf67c192012-09-21 15:09:37 -050038NOVA_STATE_PATH=${NOVA_STATE_PATH:=$DATA_DIR/nova}
39# INSTANCES_PATH is the previous name for this
40NOVA_INSTANCES_PATH=${NOVA_INSTANCES_PATH:=${INSTANCES_PATH:=$NOVA_STATE_PATH/instances}}
Dean Troyerbc071bc2012-10-01 14:06:44 -050041NOVA_AUTH_CACHE_DIR=${NOVA_AUTH_CACHE_DIR:-/var/cache/nova}
Dean Troyerbf67c192012-09-21 15:09:37 -050042
43NOVA_CONF_DIR=/etc/nova
44NOVA_CONF=$NOVA_CONF_DIR/nova.conf
Kieran Spearfb2a3ae2013-03-11 23:55:49 +000045NOVA_CELLS_CONF=$NOVA_CONF_DIR/nova-cells.conf
Chris Dent2f27a0e2014-09-09 13:46:02 +010046NOVA_FAKE_CONF=$NOVA_CONF_DIR/nova-fake.conf
Kieran Spearfb2a3ae2013-03-11 23:55:49 +000047NOVA_CELLS_DB=${NOVA_CELLS_DB:-nova_cell}
48
Dean Troyerbf67c192012-09-21 15:09:37 -050049NOVA_API_PASTE_INI=${NOVA_API_PASTE_INI:-$NOVA_CONF_DIR/api-paste.ini}
Ken'ichi Ohmichia8836982014-12-04 23:08:10 +000050# NOVA_API_VERSION valid options
Ken'ichi Ohmichi0f176d82014-12-03 01:24:47 +000051# - default - setup API end points as nova does out of the box
52# - v21default - make v21 the default on /v2
53# NOTE(sdague): this is for transitional testing of the Nova v21 API.
54# Expect to remove in L or M.
Ken'ichi Ohmichia8836982014-12-04 23:08:10 +000055NOVA_API_VERSION=${NOVA_API_VERSION-default}
Dean Troyerbf67c192012-09-21 15:09:37 -050056
Rob Crittenden18d47782014-03-19 17:47:42 -040057if is_ssl_enabled_service "nova" || is_service_enabled tls-proxy; then
58 NOVA_SERVICE_PROTOCOL="https"
59 EC2_SERVICE_PROTOCOL="https"
60else
61 EC2_SERVICE_PROTOCOL="http"
62fi
63
Dean Troyer3a3a2ba2012-12-11 15:26:24 -060064# Public facing bits
65NOVA_SERVICE_HOST=${NOVA_SERVICE_HOST:-$SERVICE_HOST}
66NOVA_SERVICE_PORT=${NOVA_SERVICE_PORT:-8774}
67NOVA_SERVICE_PORT_INT=${NOVA_SERVICE_PORT_INT:-18774}
68NOVA_SERVICE_PROTOCOL=${NOVA_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
Rob Crittenden18d47782014-03-19 17:47:42 -040069EC2_SERVICE_PORT=${EC2_SERVICE_PORT:-8773}
70EC2_SERVICE_PORT_INT=${EC2_SERVICE_PORT_INT:-18773}
Dean Troyer3a3a2ba2012-12-11 15:26:24 -060071
Dean Troyerbf67c192012-09-21 15:09:37 -050072# Support entry points installation of console scripts
73if [[ -d $NOVA_DIR/bin ]]; then
74 NOVA_BIN_DIR=$NOVA_DIR/bin
75else
Jakub Ruzicka4196d552013-01-30 15:35:54 +010076 NOVA_BIN_DIR=$(get_python_exec_prefix)
Dean Troyerbf67c192012-09-21 15:09:37 -050077fi
78
79# Set the paths of certain binaries
Vincent Untz856a11e2012-11-21 16:04:12 +010080NOVA_ROOTWRAP=$(get_rootwrap_location nova)
Dean Troyerbf67c192012-09-21 15:09:37 -050081
Dan Prince24f6efa2013-10-31 10:27:58 -040082# Option to enable/disable config drive
83# NOTE: Set FORCE_CONFIG_DRIVE="False" to turn OFF config drive
84FORCE_CONFIG_DRIVE=${FORCE_CONFIG_DRIVE:-"always"}
85
Dean Troyerbf67c192012-09-21 15:09:37 -050086# Nova supports pluggable schedulers. The default ``FilterScheduler``
87# should work in most cases.
88SCHEDULER=${SCHEDULER:-nova.scheduler.filter_scheduler.FilterScheduler}
89
90QEMU_CONF=/etc/libvirt/qemu.conf
91
Dean Troyer8c032d12013-09-23 13:53:13 -050092# Set default defaults here as some hypervisor drivers override these
93PUBLIC_INTERFACE_DEFAULT=br100
Dean Troyer8c032d12013-09-23 13:53:13 -050094FLAT_NETWORK_BRIDGE_DEFAULT=br100
Sean Dague11007172014-05-28 17:30:10 -040095# set the GUEST_INTERFACE_DEFAULT to some interface on the box so that
96# the default isn't completely crazy. This will match eth*, em*, or
97# the new p* interfaces, then basically picks the first
98# alphabetically. It's probably wrong, however it's less wrong than
99# always using 'eth0' which doesn't exist on new Linux distros at all.
Sean Daguefdb920c2014-06-05 19:06:05 -0400100GUEST_INTERFACE_DEFAULT=$(ip link \
101 | grep 'state UP' \
102 | awk '{print $2}' \
103 | sed 's/://' \
104 | grep ^[ep] \
105 | head -1)
Dean Troyer8c032d12013-09-23 13:53:13 -0500106
Robbie Harwood (frozencemetery)4e07fdc2014-07-14 18:11:39 -0400107# $NOVA_VNC_ENABLED can be used to forcibly enable vnc configuration.
108# In multi-node setups allows compute hosts to not run n-novnc.
109NOVA_VNC_ENABLED=$(trueorfalse False $NOVA_VNC_ENABLED)
110
Dean Troyer8c032d12013-09-23 13:53:13 -0500111# Get hypervisor configuration
112# ----------------------------
113
114NOVA_PLUGINS=$TOP_DIR/lib/nova_plugins
115if is_service_enabled nova && [[ -r $NOVA_PLUGINS/hypervisor-$VIRT_DRIVER ]]; then
116 # Load plugin
117 source $NOVA_PLUGINS/hypervisor-$VIRT_DRIVER
118fi
119
Dean Troyerbf67c192012-09-21 15:09:37 -0500120
Dean Troyerb3236912013-03-17 15:17:05 -0500121# Nova Network Configuration
122# --------------------------
123
Dean Troyerb3236912013-03-17 15:17:05 -0500124NETWORK_MANAGER=${NETWORK_MANAGER:-${NET_MAN:-FlatDHCPManager}}
125PUBLIC_INTERFACE=${PUBLIC_INTERFACE:-$PUBLIC_INTERFACE_DEFAULT}
126VLAN_INTERFACE=${VLAN_INTERFACE:-$GUEST_INTERFACE_DEFAULT}
127FLAT_NETWORK_BRIDGE=${FLAT_NETWORK_BRIDGE:-$FLAT_NETWORK_BRIDGE_DEFAULT}
128EC2_DMZ_HOST=${EC2_DMZ_HOST:-$SERVICE_HOST}
129
130# If you are using the FlatDHCP network mode on multiple hosts, set the
131# ``FLAT_INTERFACE`` variable but make sure that the interface doesn't already
132# have an IP or you risk breaking things.
133#
134# **DHCP Warning**: If your flat interface device uses DHCP, there will be a
135# hiccup while the network is moved from the flat interface to the flat network
136# bridge. This will happen when you launch your first instance. Upon launch
137# you will lose all connectivity to the node, and the VM launch will probably
138# fail.
139#
140# If you are running on a single node and don't need to access the VMs from
141# devices other than that node, you can set ``FLAT_INTERFACE=``
142# This will stop nova from bridging any interfaces into ``FLAT_NETWORK_BRIDGE``.
Davanum Srinivasb93b74c2013-03-21 21:25:05 -0400143FLAT_INTERFACE=${FLAT_INTERFACE:-$GUEST_INTERFACE_DEFAULT}
Dean Troyerb3236912013-03-17 15:17:05 -0500144
145# ``MULTI_HOST`` is a mode where each compute node runs its own network node. This
146# allows network operations and routing for a VM to occur on the server that is
147# running the VM - removing a SPOF and bandwidth bottleneck.
148MULTI_HOST=`trueorfalse False $MULTI_HOST`
149
Joe Gordon18d62982014-10-28 13:37:15 -0700150# ``NOVA_ALLOW_MOVE_TO_SAME_HOST` can be set to False in multi node devstack,
151# where there are at least two nova-computes.
152NOVA_ALLOW_MOVE_TO_SAME_HOST=`trueorfalse True $NOVA_ALLOW_MOVE_TO_SAME_HOST`
153
Dean Troyerb3236912013-03-17 15:17:05 -0500154# Test floating pool and range are used for testing. They are defined
155# here until the admin APIs can replace nova-manage
156TEST_FLOATING_POOL=${TEST_FLOATING_POOL:-test}
157TEST_FLOATING_RANGE=${TEST_FLOATING_RANGE:-192.168.253.0/29}
158
Dean Troyer4237f592014-01-29 16:22:11 -0600159# Tell Tempest this project is present
160TEMPEST_SERVICES+=,nova
161
Dean Troyerb3236912013-03-17 15:17:05 -0500162
Dean Troyercc6b4432013-04-08 15:38:03 -0500163# Functions
164# ---------
Dean Troyerbf67c192012-09-21 15:09:37 -0500165
Dean Troyere4fa7212014-01-15 15:04:49 -0600166# Test if any Nova services are enabled
167# is_nova_enabled
168function is_nova_enabled {
169 [[ ,${ENABLED_SERVICES} =~ ,"n-" ]] && return 0
170 return 1
171}
172
173# Test if any Nova Cell services are enabled
174# is_nova_enabled
175function is_n-cell_enabled {
Joe Gordon6b2f2652014-03-26 19:19:01 -0700176 [[ ,${ENABLED_SERVICES} =~ ,"n-cell" ]] && return 0
Dean Troyere4fa7212014-01-15 15:04:49 -0600177 return 1
178}
179
Dean Troyerbf67c192012-09-21 15:09:37 -0500180# Helper to clean iptables rules
Ian Wienandaee18c72014-02-21 15:35:08 +1100181function clean_iptables {
Dean Troyerbf67c192012-09-21 15:09:37 -0500182 # Delete rules
183 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
184 # Delete nat rules
185 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
186 # Delete chains
187 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
188 # Delete nat chains
189 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
190}
191
192# cleanup_nova() - Remove residual data files, anything left over from previous
193# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100194function cleanup_nova {
Dean Troyerbf67c192012-09-21 15:09:37 -0500195 if is_service_enabled n-cpu; then
196 # Clean iptables from previous runs
197 clean_iptables
198
199 # Destroy old instances
Dean Troyer0038a1a2014-07-25 15:27:54 -0500200 local 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 -0500201 if [ ! "$instances" = "" ]; then
202 echo $instances | xargs -n1 sudo virsh destroy || true
Daniel P. Berranged52008a2013-05-20 15:03:43 +0100203 echo $instances | xargs -n1 sudo virsh undefine --managed-save || true
Dean Troyerbf67c192012-09-21 15:09:37 -0500204 fi
205
206 # Logout and delete iscsi sessions
Dean Troyer0038a1a2014-07-25 15:27:54 -0500207 local tgts=$(sudo iscsiadm --mode node | grep $VOLUME_NAME_PREFIX | cut -d ' ' -f2)
208 local target
Dan Smithc0fad2b2013-03-28 12:22:25 -0700209 for target in $tgts; do
210 sudo iscsiadm --mode node -T $target --logout || true
211 done
212 sudo iscsiadm --mode node --op delete || true
Dean Troyerbf67c192012-09-21 15:09:37 -0500213
214 # Clean out the instances directory.
215 sudo rm -rf $NOVA_INSTANCES_PATH/*
216 fi
Dean Troyer995eb922013-03-07 16:11:40 -0600217
218 sudo rm -rf $NOVA_STATE_PATH $NOVA_AUTH_CACHE_DIR
Dean Troyer2aa2a892013-08-04 19:53:19 -0500219
220 # NOTE(dtroyer): This really should be called from here but due to the way
221 # nova abuses the _cleanup() function we're moving it
222 # directly into cleanup.sh until this can be fixed.
223 #if is_service_enabled n-cpu && [[ -r $NOVA_PLUGINS/hypervisor-$VIRT_DRIVER ]]; then
224 # cleanup_nova_hypervisor
225 #fi
Dean Troyerbf67c192012-09-21 15:09:37 -0500226}
227
Dean Troyerbf67c192012-09-21 15:09:37 -0500228# configure_nova_rootwrap() - configure Nova's rootwrap
Ian Wienandaee18c72014-02-21 15:35:08 +1100229function configure_nova_rootwrap {
Dean Troyerbf67c192012-09-21 15:09:37 -0500230 # Deploy new rootwrap filters files (owned by root).
231 # Wipe any existing rootwrap.d files first
232 if [[ -d $NOVA_CONF_DIR/rootwrap.d ]]; then
233 sudo rm -rf $NOVA_CONF_DIR/rootwrap.d
234 fi
235 # Deploy filters to /etc/nova/rootwrap.d
236 sudo mkdir -m 755 $NOVA_CONF_DIR/rootwrap.d
237 sudo cp $NOVA_DIR/etc/nova/rootwrap.d/*.filters $NOVA_CONF_DIR/rootwrap.d
238 sudo chown -R root:root $NOVA_CONF_DIR/rootwrap.d
239 sudo chmod 644 $NOVA_CONF_DIR/rootwrap.d/*
240 # Set up rootwrap.conf, pointing to /etc/nova/rootwrap.d
241 sudo cp $NOVA_DIR/etc/nova/rootwrap.conf $NOVA_CONF_DIR/
242 sudo sed -e "s:^filters_path=.*$:filters_path=$NOVA_CONF_DIR/rootwrap.d:" -i $NOVA_CONF_DIR/rootwrap.conf
243 sudo chown root:root $NOVA_CONF_DIR/rootwrap.conf
244 sudo chmod 0644 $NOVA_CONF_DIR/rootwrap.conf
245 # Specify rootwrap.conf as first parameter to nova-rootwrap
Dean Troyer0038a1a2014-07-25 15:27:54 -0500246 local rootwrap_sudoer_cmd="$NOVA_ROOTWRAP $NOVA_CONF_DIR/rootwrap.conf *"
Dean Troyerbf67c192012-09-21 15:09:37 -0500247
248 # Set up the rootwrap sudoers for nova
Dean Troyer0038a1a2014-07-25 15:27:54 -0500249 local tempfile=`mktemp`
250 echo "$STACK_USER ALL=(root) NOPASSWD: $rootwrap_sudoer_cmd" >$tempfile
251 chmod 0440 $tempfile
252 sudo chown root:root $tempfile
253 sudo mv $tempfile /etc/sudoers.d/nova-rootwrap
Dean Troyerbf67c192012-09-21 15:09:37 -0500254}
255
256# configure_nova() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100257function configure_nova {
Dean Troyerbf67c192012-09-21 15:09:37 -0500258 # Put config files in ``/etc/nova`` for everyone to find
259 if [[ ! -d $NOVA_CONF_DIR ]]; then
260 sudo mkdir -p $NOVA_CONF_DIR
261 fi
Attila Fazekas91b8d132013-01-06 22:40:09 +0100262 sudo chown $STACK_USER $NOVA_CONF_DIR
Dean Troyerbf67c192012-09-21 15:09:37 -0500263
264 cp -p $NOVA_DIR/etc/nova/policy.json $NOVA_CONF_DIR
265
266 configure_nova_rootwrap
267
Joe Gordonea70cc92014-11-25 19:07:11 -0800268 if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
Dean Troyerbf67c192012-09-21 15:09:37 -0500269 # Remove legacy paste config if present
270 rm -f $NOVA_DIR/bin/nova-api-paste.ini
271
272 # Get the sample configuration file in place
273 cp $NOVA_DIR/etc/nova/api-paste.ini $NOVA_CONF_DIR
Ken'ichi Ohmichi0f176d82014-12-03 01:24:47 +0000274
275 # For testing v21 is equivalent to v2
276 if [[ "$NOVA_API_VERSION" == "v21default" ]]; then
277 sed -i s/": openstack_compute_api_v2$"/": openstack_compute_api_v21"/ "$NOVA_API_PASTE_INI"
278 fi
Dean Troyerbf67c192012-09-21 15:09:37 -0500279 fi
280
281 if is_service_enabled n-cpu; then
282 # Force IP forwarding on, just on case
283 sudo sysctl -w net.ipv4.ip_forward=1
284
Bob Ballb1e49bf2013-05-30 16:47:19 +0100285 if [[ "$VIRT_DRIVER" = 'libvirt' ]]; then
Bob Ballb1e49bf2013-05-30 16:47:19 +0100286 # Check for kvm (hardware based virtualization). If unable to initialize
287 # kvm, we drop back to the slower emulation mode (qemu). Note: many systems
288 # come with hardware virtualization disabled in BIOS.
289 if [[ "$LIBVIRT_TYPE" == "kvm" ]]; then
290 sudo modprobe kvm || true
291 if [ ! -e /dev/kvm ]; then
292 echo "WARNING: Switching to QEMU"
293 LIBVIRT_TYPE=qemu
294 if which selinuxenabled 2>&1 > /dev/null && selinuxenabled; then
295 # https://bugzilla.redhat.com/show_bug.cgi?id=753589
296 sudo setsebool virt_use_execmem on
297 fi
Dean Troyerbf67c192012-09-21 15:09:37 -0500298 fi
299 fi
Dean Troyerbf67c192012-09-21 15:09:37 -0500300
Bob Ballb1e49bf2013-05-30 16:47:19 +0100301 # Install and configure **LXC** if specified. LXC is another approach to
302 # splitting a system into many smaller parts. LXC uses cgroups and chroot
303 # to simulate multiple systems.
304 if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then
305 if is_ubuntu; then
306 if [[ ! "$DISTRO" > natty ]]; then
Dean Troyer0038a1a2014-07-25 15:27:54 -0500307 local cgline="none /cgroup cgroup cpuacct,memory,devices,cpu,freezer,blkio 0 0"
Bob Ballb1e49bf2013-05-30 16:47:19 +0100308 sudo mkdir -p /cgroup
309 if ! grep -q cgroup /etc/fstab; then
310 echo "$cgline" | sudo tee -a /etc/fstab
311 fi
312 if ! mount -n | grep -q cgroup; then
313 sudo mount /cgroup
314 fi
Dean Troyerbf67c192012-09-21 15:09:37 -0500315 fi
316 fi
317 fi
318 fi
319
Dean Troyerbf67c192012-09-21 15:09:37 -0500320 # Instance Storage
321 # ----------------
322
323 # Nova stores each instance in its own directory.
Doug Hellmanncf9eef82013-03-25 19:34:48 -0400324 sudo mkdir -p $NOVA_INSTANCES_PATH
325 sudo chown -R $STACK_USER $NOVA_INSTANCES_PATH
Dean Troyerbf67c192012-09-21 15:09:37 -0500326
327 # You can specify a different disk to be mounted and used for backing the
328 # virtual machines. If there is a partition labeled nova-instances we
329 # mount it (ext filesystems can be labeled via e2label).
330 if [ -L /dev/disk/by-label/nova-instances ]; then
331 if ! mount -n | grep -q $NOVA_INSTANCES_PATH; then
332 sudo mount -L nova-instances $NOVA_INSTANCES_PATH
Attila Fazekas91b8d132013-01-06 22:40:09 +0100333 sudo chown -R $STACK_USER $NOVA_INSTANCES_PATH
Dean Troyerbf67c192012-09-21 15:09:37 -0500334 fi
335 fi
Ralf Haferkamp65aaa182014-04-15 17:40:26 +0200336 if is_suse; then
337 # iscsid is not started by default
338 start_service iscsid
339 fi
Dean Troyerbf67c192012-09-21 15:09:37 -0500340 fi
Dean Troyer8c032d12013-09-23 13:53:13 -0500341
342 # Rebuild the config file from scratch
343 create_nova_conf
344
Sergey Skripnicka99b8692014-03-05 14:47:58 +0200345 if is_service_enabled n-cpu && [[ -r $NOVA_PLUGINS/hypervisor-$VIRT_DRIVER ]]; then
Dean Troyer8c032d12013-09-23 13:53:13 -0500346 # Configure hypervisor plugin
347 configure_nova_hypervisor
348 fi
Dean Troyerbf67c192012-09-21 15:09:37 -0500349}
350
Dean Troyera0dce262012-12-11 16:52:37 -0600351# create_nova_accounts() - Set up common required nova accounts
Chris Dent67bc8e82014-10-08 12:07:46 +0100352#
Dean Troyer42a59c22014-03-03 14:31:29 -0600353# Project User Roles
Dean Troyera0dce262012-12-11 16:52:37 -0600354# ------------------------------------------------------------------
Dean Troyer42a59c22014-03-03 14:31:29 -0600355# SERVICE_TENANT_NAME nova admin
356# SERVICE_TENANT_NAME nova ResellerAdmin (if Swift is enabled)
Chris Dent67bc8e82014-10-08 12:07:46 +0100357function create_nova_accounts {
Dean Troyera0dce262012-12-11 16:52:37 -0600358
Dean Troyer0038a1a2014-07-25 15:27:54 -0500359 local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
360 local admin_role=$(openstack role list | awk "/ admin / { print \$2 }")
Dean Troyera0dce262012-12-11 16:52:37 -0600361
362 # Nova
363 if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100364
Dean Troyer0038a1a2014-07-25 15:27:54 -0500365 local nova_user=$(get_or_create_user "nova" \
366 "$SERVICE_PASSWORD" $service_tenant)
367 get_or_add_user_role $admin_role $nova_user $service_tenant
Bartosz Górski0abde392014-02-28 14:15:19 +0100368
Dean Troyera0dce262012-12-11 16:52:37 -0600369 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100370
Dean Troyer0038a1a2014-07-25 15:27:54 -0500371 local nova_service=$(get_or_create_service "nova" \
Bartosz Górski0abde392014-02-28 14:15:19 +0100372 "compute" "Nova Compute Service")
Dean Troyer0038a1a2014-07-25 15:27:54 -0500373 get_or_create_endpoint $nova_service \
Bartosz Górski0abde392014-02-28 14:15:19 +0100374 "$REGION_NAME" \
375 "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2/\$(tenant_id)s" \
376 "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2/\$(tenant_id)s" \
377 "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2/\$(tenant_id)s"
Ken'ichi Ohmichi3feaa382014-09-25 00:49:57 +0000378
379 local nova_v21_service=$(get_or_create_service "novav21" \
380 "computev21" "Nova Compute Service V2.1")
381 get_or_create_endpoint $nova_v21_service \
382 "$REGION_NAME" \
383 "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2.1/\$(tenant_id)s" \
384 "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2.1/\$(tenant_id)s" \
385 "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2.1/\$(tenant_id)s"
Dean Troyera0dce262012-12-11 16:52:37 -0600386 fi
387 fi
Dean Troyer42a59c22014-03-03 14:31:29 -0600388
389 if is_service_enabled n-api; then
390 # Swift
391 if is_service_enabled swift; then
392 # Nova needs ResellerAdmin role to download images when accessing
393 # swift through the s3 api.
Bartosz Górski0abde392014-02-28 14:15:19 +0100394 get_or_add_user_role ResellerAdmin nova $SERVICE_TENANT_NAME
Dean Troyer42a59c22014-03-03 14:31:29 -0600395 fi
396
397 # EC2
398 if [[ "$KEYSTONE_CATALOG_BACKEND" = "sql" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100399
Dean Troyer0038a1a2014-07-25 15:27:54 -0500400 local ec2_service=$(get_or_create_service "ec2" \
Bartosz Górski0abde392014-02-28 14:15:19 +0100401 "ec2" "EC2 Compatibility Layer")
Dean Troyer0038a1a2014-07-25 15:27:54 -0500402 get_or_create_endpoint $ec2_service \
Bartosz Górski0abde392014-02-28 14:15:19 +0100403 "$REGION_NAME" \
Rob Crittenden18d47782014-03-19 17:47:42 -0400404 "$EC2_SERVICE_PROTOCOL://$SERVICE_HOST:8773/services/Cloud" \
405 "$EC2_SERVICE_PROTOCOL://$SERVICE_HOST:8773/services/Admin" \
406 "$EC2_SERVICE_PROTOCOL://$SERVICE_HOST:8773/services/Cloud"
Dean Troyer42a59c22014-03-03 14:31:29 -0600407 fi
408 fi
409
410 # S3
411 if is_service_enabled n-obj swift3; then
412 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100413
Dean Troyer0038a1a2014-07-25 15:27:54 -0500414 local s3_service=$(get_or_create_service "s3" "s3" "S3")
415 get_or_create_endpoint $s3_service \
Bartosz Górski0abde392014-02-28 14:15:19 +0100416 "$REGION_NAME" \
417 "http://$SERVICE_HOST:$S3_SERVICE_PORT" \
418 "http://$SERVICE_HOST:$S3_SERVICE_PORT" \
419 "http://$SERVICE_HOST:$S3_SERVICE_PORT"
Dean Troyer42a59c22014-03-03 14:31:29 -0600420 fi
421 fi
Dean Troyera0dce262012-12-11 16:52:37 -0600422}
423
Dean Troyerda7b8092012-10-08 18:12:14 -0500424# create_nova_conf() - Create a new nova.conf file
Ian Wienandaee18c72014-02-21 15:35:08 +1100425function create_nova_conf {
Dean Troyerbf67c192012-09-21 15:09:37 -0500426 # Remove legacy ``nova.conf``
427 rm -f $NOVA_DIR/bin/nova.conf
428
429 # (Re)create ``nova.conf``
Dean Troyer3cf1ffb2012-10-02 11:51:27 -0500430 rm -f $NOVA_CONF
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800431 iniset $NOVA_CONF DEFAULT verbose "True"
Ben Nemec03997942013-08-10 09:56:16 -0500432 iniset $NOVA_CONF DEFAULT debug "$ENABLE_DEBUG_LOG_LEVEL"
Joe Gordon18d62982014-10-28 13:37:15 -0700433 if [ "$NOVA_ALLOW_MOVE_TO_SAME_HOST" == "True" ]; then
434 iniset $NOVA_CONF DEFAULT allow_resize_to_same_host "True"
435 iniset $NOVA_CONF DEFAULT allow_migrate_to_same_host "True"
436 fi
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800437 iniset $NOVA_CONF DEFAULT api_paste_config "$NOVA_API_PASTE_INI"
438 iniset $NOVA_CONF DEFAULT rootwrap_config "$NOVA_CONF_DIR/rootwrap.conf"
Scott Moser50686e52013-07-17 11:32:35 -0400439 iniset $NOVA_CONF DEFAULT scheduler_driver "$SCHEDULER"
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800440 iniset $NOVA_CONF DEFAULT dhcpbridge_flagfile "$NOVA_CONF"
441 iniset $NOVA_CONF DEFAULT force_dhcp_release "True"
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800442 iniset $NOVA_CONF DEFAULT default_floating_pool "$PUBLIC_NETWORK_NAME"
443 iniset $NOVA_CONF DEFAULT s3_host "$SERVICE_HOST"
444 iniset $NOVA_CONF DEFAULT s3_port "$S3_SERVICE_PORT"
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800445 iniset $NOVA_CONF DEFAULT my_ip "$HOST_IP"
Attila Fazekas7e79d912013-03-03 12:23:04 +0100446 iniset $NOVA_CONF DEFAULT sql_connection `database_connection_url nova`
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800447 iniset $NOVA_CONF DEFAULT instance_name_template "${INSTANCE_NAME_PREFIX}%08x"
Chris Yeoh1b4d91b2013-06-03 16:23:01 +0930448 iniset $NOVA_CONF osapi_v3 enabled "True"
Dean Troyerbf67c192012-09-21 15:09:37 -0500449
Ralf Haferkamp55dd68a2014-04-11 17:08:28 +0200450 if is_fedora || is_suse; then
451 # nova defaults to /usr/local/bin, but fedora and suse pip like to
Ian Wienand00fd79d2013-06-06 11:19:16 +1000452 # install things in /usr/bin
453 iniset $NOVA_CONF DEFAULT bindir "/usr/bin"
454 fi
455
Dean Troyerbf67c192012-09-21 15:09:37 -0500456 if is_service_enabled n-api; then
Joe Gordond73af872014-02-06 15:33:52 -0800457 if is_service_enabled n-api-meta; then
458 # If running n-api-meta as a separate service
459 NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/,metadata//")
460 fi
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800461 iniset $NOVA_CONF DEFAULT enabled_apis "$NOVA_ENABLED_APIS"
Dean Troyer3a3a2ba2012-12-11 15:26:24 -0600462 if is_service_enabled tls-proxy; then
463 # Set the service port for a proxy to take the original
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800464 iniset $NOVA_CONF DEFAULT osapi_compute_listen_port "$NOVA_SERVICE_PORT_INT"
Dean Troyer3a3a2ba2012-12-11 15:26:24 -0600465 fi
Dan Prince741fc5c2013-10-16 17:48:16 -0400466
Brant Knudson05952372014-09-19 17:22:22 -0500467 configure_auth_token_middleware $NOVA_CONF nova $NOVA_AUTH_CACHE_DIR
Dean Troyerbf67c192012-09-21 15:09:37 -0500468 fi
Dan Prince741fc5c2013-10-16 17:48:16 -0400469
Rob Crittenden18d47782014-03-19 17:47:42 -0400470 if is_service_enabled cinder; then
Rob Crittenden18d47782014-03-19 17:47:42 -0400471 if is_ssl_enabled_service "cinder" || is_service_enabled tls-proxy; then
472 CINDER_SERVICE_HOST=${CINDER_SERVICE_HOST:-$SERVICE_HOST}
473 CINDER_SERVICE_PORT=${CINDER_SERVICE_PORT:-8776}
Jamie Lennox55c7ebb2014-11-25 12:08:55 +1000474 iniset $NOVA_CONF cinder cafile $SSL_BUNDLE_FILE
Rob Crittenden18d47782014-03-19 17:47:42 -0400475 fi
476 fi
477
Dean Troyerbf67c192012-09-21 15:09:37 -0500478 if [ -n "$NOVA_STATE_PATH" ]; then
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800479 iniset $NOVA_CONF DEFAULT state_path "$NOVA_STATE_PATH"
480 iniset $NOVA_CONF DEFAULT lock_path "$NOVA_STATE_PATH"
Dean Troyerbf67c192012-09-21 15:09:37 -0500481 fi
482 if [ -n "$NOVA_INSTANCES_PATH" ]; then
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800483 iniset $NOVA_CONF DEFAULT instances_path "$NOVA_INSTANCES_PATH"
Dean Troyerbf67c192012-09-21 15:09:37 -0500484 fi
485 if [ "$MULTI_HOST" != "False" ]; then
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800486 iniset $NOVA_CONF DEFAULT multi_host "True"
487 iniset $NOVA_CONF DEFAULT send_arp_for_ha "True"
Dean Troyerbf67c192012-09-21 15:09:37 -0500488 fi
489 if [ "$SYSLOG" != "False" ]; then
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800490 iniset $NOVA_CONF DEFAULT use_syslog "True"
Dean Troyerbf67c192012-09-21 15:09:37 -0500491 fi
Dan Prince24f6efa2013-10-31 10:27:58 -0400492 if [ "$FORCE_CONFIG_DRIVE" != "False" ]; then
493 iniset $NOVA_CONF DEFAULT force_config_drive "$FORCE_CONFIG_DRIVE"
494 fi
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700495 # Format logging
Dean Troyerbf67c192012-09-21 15:09:37 -0500496 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700497 setup_colorized_logging $NOVA_CONF DEFAULT
Dean Troyerbf67c192012-09-21 15:09:37 -0500498 else
499 # Show user_name and project_name instead of user_id and project_id
Joe Gordon07db7132013-01-30 13:07:25 -0800500 iniset $NOVA_CONF DEFAULT logging_context_format_string "%(asctime)s.%(msecs)03d %(levelname)s %(name)s [%(request_id)s %(user_name)s %(project_name)s] %(instance)s%(message)s"
Dean Troyerbf67c192012-09-21 15:09:37 -0500501 fi
Eoghan Glynn1fcc6a12012-10-25 14:57:14 +0000502 if is_service_enabled ceilometer; then
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800503 iniset $NOVA_CONF DEFAULT instance_usage_audit "True"
504 iniset $NOVA_CONF DEFAULT instance_usage_audit_period "hour"
Julien Danjoua9787d02013-07-02 11:30:40 +0200505 iniset $NOVA_CONF DEFAULT notify_on_state_change "vm_and_task_state"
Julien Danjouca920572014-02-03 15:26:20 +0100506 iniset $NOVA_CONF DEFAULT notification_driver "messaging"
Eoghan Glynn1fcc6a12012-10-25 14:57:14 +0000507 fi
508
Dean Troyerb3236912013-03-17 15:17:05 -0500509 # All nova-compute workers need to know the vnc configuration options
510 # These settings don't hurt anything if n-xvnc and n-novnc are disabled
511 if is_service_enabled n-cpu; then
512 NOVNCPROXY_URL=${NOVNCPROXY_URL:-"http://$SERVICE_HOST:6080/vnc_auto.html"}
513 iniset $NOVA_CONF DEFAULT novncproxy_base_url "$NOVNCPROXY_URL"
514 XVPVNCPROXY_URL=${XVPVNCPROXY_URL:-"http://$SERVICE_HOST:6081/console"}
515 iniset $NOVA_CONF DEFAULT xvpvncproxy_base_url "$XVPVNCPROXY_URL"
516 SPICEHTML5PROXY_URL=${SPICEHTML5PROXY_URL:-"http://$SERVICE_HOST:6082/spice_auto.html"}
517 iniset $NOVA_CONF spice html5proxy_base_url "$SPICEHTML5PROXY_URL"
518 fi
Dean Troyerb3236912013-03-17 15:17:05 -0500519
Robbie Harwood (frozencemetery)4e07fdc2014-07-14 18:11:39 -0400520 if is_service_enabled n-novnc || is_service_enabled n-xvnc || [ "$NOVA_VNC_ENABLED" != False ]; then
Sean Dague101b4242013-10-22 08:47:11 -0400521 # Address on which instance vncservers will listen on compute hosts.
522 # For multi-host, this should be the management ip of the compute host.
523 VNCSERVER_LISTEN=${VNCSERVER_LISTEN=127.0.0.1}
524 VNCSERVER_PROXYCLIENT_ADDRESS=${VNCSERVER_PROXYCLIENT_ADDRESS=127.0.0.1}
525 iniset $NOVA_CONF DEFAULT vnc_enabled true
526 iniset $NOVA_CONF DEFAULT vncserver_listen "$VNCSERVER_LISTEN"
527 iniset $NOVA_CONF DEFAULT vncserver_proxyclient_address "$VNCSERVER_PROXYCLIENT_ADDRESS"
Dean Troyerb3236912013-03-17 15:17:05 -0500528 else
Sean Dague101b4242013-10-22 08:47:11 -0400529 iniset $NOVA_CONF DEFAULT vnc_enabled false
Dean Troyerb3236912013-03-17 15:17:05 -0500530 fi
531
532 if is_service_enabled n-spice; then
Sean Dague101b4242013-10-22 08:47:11 -0400533 # Address on which instance spiceservers will listen on compute hosts.
534 # For multi-host, this should be the management ip of the compute host.
535 SPICESERVER_PROXYCLIENT_ADDRESS=${SPICESERVER_PROXYCLIENT_ADDRESS=127.0.0.1}
536 SPICESERVER_LISTEN=${SPICESERVER_LISTEN=127.0.0.1}
537 iniset $NOVA_CONF spice enabled true
538 iniset $NOVA_CONF spice server_listen "$SPICESERVER_LISTEN"
539 iniset $NOVA_CONF spice server_proxyclient_address "$SPICESERVER_PROXYCLIENT_ADDRESS"
Dean Troyerb3236912013-03-17 15:17:05 -0500540 else
Sean Dague101b4242013-10-22 08:47:11 -0400541 iniset $NOVA_CONF spice enabled false
Dean Troyerb3236912013-03-17 15:17:05 -0500542 fi
543
544 iniset $NOVA_CONF DEFAULT ec2_dmz_host "$EC2_DMZ_HOST"
Rob Crittenden18d47782014-03-19 17:47:42 -0400545 iniset $NOVA_CONF DEFAULT keystone_ec2_url $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0/ec2tokens
Dean Troyerb3236912013-03-17 15:17:05 -0500546 iniset_rpc_backend nova $NOVA_CONF DEFAULT
Rob Crittenden18d47782014-03-19 17:47:42 -0400547 iniset $NOVA_CONF glance api_servers "${GLANCE_SERVICE_PROTOCOL}://${GLANCE_HOSTPORT}"
Bob Ball2f720502014-08-28 14:50:04 +0100548
Joe Gordon1f79bad2014-09-26 09:59:47 -0700549 iniset $NOVA_CONF DEFAULT osapi_compute_workers "$API_WORKERS"
Dean Troyer05bd7b82014-09-16 17:25:33 -0500550 iniset $NOVA_CONF DEFAULT ec2_workers "$API_WORKERS"
551 iniset $NOVA_CONF DEFAULT metadata_workers "$API_WORKERS"
Rob Crittenden18d47782014-03-19 17:47:42 -0400552
553 if is_ssl_enabled_service glance || is_service_enabled tls-proxy; then
554 iniset $NOVA_CONF DEFAULT glance_protocol https
555 fi
556
557 # Register SSL certificates if provided
558 if is_ssl_enabled_service nova; then
559 ensure_certificates NOVA
560
561 iniset $NOVA_CONF DEFAULT ssl_cert_file "$NOVA_SSL_CERT"
562 iniset $NOVA_CONF DEFAULT ssl_key_file "$NOVA_SSL_KEY"
563
564 iniset $NOVA_CONF DEFAULT enabled_ssl_apis "$NOVA_ENABLED_APIS"
565 fi
566
567 if is_service_enabled tls-proxy; then
568 iniset $NOVA_CONF DEFAULT ec2_listen_port $EC2_SERVICE_PORT_INT
569 fi
Dean Troyerda7b8092012-10-08 18:12:14 -0500570}
Dean Troyerbf67c192012-09-21 15:09:37 -0500571
Ian Wienandaee18c72014-02-21 15:35:08 +1100572function init_nova_cells {
Kieran Spearfb2a3ae2013-03-11 23:55:49 +0000573 if is_service_enabled n-cell; then
574 cp $NOVA_CONF $NOVA_CELLS_CONF
575 iniset $NOVA_CELLS_CONF DEFAULT sql_connection `database_connection_url $NOVA_CELLS_DB`
576 iniset $NOVA_CELLS_CONF DEFAULT rabbit_virtual_host child_cell
577 iniset $NOVA_CELLS_CONF DEFAULT dhcpbridge_flagfile $NOVA_CELLS_CONF
578 iniset $NOVA_CELLS_CONF cells enable True
Chris Behrensc62c2b92013-07-24 03:56:13 -0700579 iniset $NOVA_CELLS_CONF cells cell_type compute
Kieran Spearfb2a3ae2013-03-11 23:55:49 +0000580 iniset $NOVA_CELLS_CONF cells name child
581
Kieran Spearfb2a3ae2013-03-11 23:55:49 +0000582 iniset $NOVA_CONF cells enable True
Chris Behrensc62c2b92013-07-24 03:56:13 -0700583 iniset $NOVA_CONF cells cell_type api
Kieran Spearfb2a3ae2013-03-11 23:55:49 +0000584 iniset $NOVA_CONF cells name region
585
586 if is_service_enabled n-api-meta; then
587 NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/,metadata//")
588 iniset $NOVA_CONF DEFAULT enabled_apis $NOVA_ENABLED_APIS
589 iniset $NOVA_CELLS_CONF DEFAULT enabled_apis metadata
590 fi
591
592 $NOVA_BIN_DIR/nova-manage --config-file $NOVA_CELLS_CONF db sync
593 $NOVA_BIN_DIR/nova-manage --config-file $NOVA_CELLS_CONF cell create --name=region --cell_type=parent --username=guest --hostname=$RABBIT_HOST --port=5672 --password=$RABBIT_PASSWORD --virtual_host=/ --woffset=0 --wscale=1
594 $NOVA_BIN_DIR/nova-manage cell create --name=child --cell_type=child --username=guest --hostname=$RABBIT_HOST --port=5672 --password=$RABBIT_PASSWORD --virtual_host=child_cell --woffset=0 --wscale=1
595 fi
596}
597
Dean Troyerf03bafe2013-02-12 10:58:28 -0600598# create_nova_cache_dir() - Part of the init_nova() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100599function create_nova_cache_dir {
Dean Troyerf03bafe2013-02-12 10:58:28 -0600600 # Create cache dir
601 sudo mkdir -p $NOVA_AUTH_CACHE_DIR
602 sudo chown $STACK_USER $NOVA_AUTH_CACHE_DIR
603 rm -f $NOVA_AUTH_CACHE_DIR/*
604}
605
Ian Wienandaee18c72014-02-21 15:35:08 +1100606function create_nova_conf_nova_network {
Dean Troyerb3236912013-03-17 15:17:05 -0500607 iniset $NOVA_CONF DEFAULT network_manager "nova.network.manager.$NETWORK_MANAGER"
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800608 iniset $NOVA_CONF DEFAULT public_interface "$PUBLIC_INTERFACE"
609 iniset $NOVA_CONF DEFAULT vlan_interface "$VLAN_INTERFACE"
610 iniset $NOVA_CONF DEFAULT flat_network_bridge "$FLAT_NETWORK_BRIDGE"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900611 if [ -n "$FLAT_INTERFACE" ]; then
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800612 iniset $NOVA_CONF DEFAULT flat_interface "$FLAT_INTERFACE"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900613 fi
614}
615
Dean Troyerf03bafe2013-02-12 10:58:28 -0600616# create_nova_keys_dir() - Part of the init_nova() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100617function create_nova_keys_dir {
Dean Troyerf03bafe2013-02-12 10:58:28 -0600618 # Create keys dir
619 sudo mkdir -p ${NOVA_STATE_PATH}/keys
620 sudo chown -R $STACK_USER ${NOVA_STATE_PATH}
621}
622
Dean Troyerda7b8092012-10-08 18:12:14 -0500623# init_nova() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100624function init_nova {
Dean Troyerf03bafe2013-02-12 10:58:28 -0600625 # All nova components talk to a central database.
626 # Only do this step once on the API node for an entire cluster.
Bob Melanderc439b5d2012-12-19 14:49:34 +0100627 if is_service_enabled $DATABASE_BACKENDS && is_service_enabled n-api; then
Dean Troyerbf67c192012-09-21 15:09:37 -0500628 # (Re)create nova database
Dean Troyerbf67c192012-09-21 15:09:37 -0500629 # Explicitly use latin1: to avoid lp#829209, nova expects the database to
630 # use latin1 by default, and then upgrades the database to utf8 (see the
631 # 082_essex.py in nova)
Terry Wilson428af5a2012-11-01 16:12:39 -0400632 recreate_database nova latin1
Dean Troyerbf67c192012-09-21 15:09:37 -0500633
Dean Troyerf03bafe2013-02-12 10:58:28 -0600634 # Migrate nova database
Dean Troyerbf67c192012-09-21 15:09:37 -0500635 $NOVA_BIN_DIR/nova-manage db sync
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800636
Kieran Spearfb2a3ae2013-03-11 23:55:49 +0000637 if is_service_enabled n-cell; then
638 recreate_database $NOVA_CELLS_DB latin1
639 fi
Dean Troyerbf67c192012-09-21 15:09:37 -0500640 fi
641
Dean Troyerf03bafe2013-02-12 10:58:28 -0600642 create_nova_cache_dir
643 create_nova_keys_dir
Dean Troyerbf67c192012-09-21 15:09:37 -0500644}
645
646# install_novaclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100647function install_novaclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500648 if use_library_from_git "python-novaclient"; then
649 git_clone_by_name "python-novaclient"
650 setup_dev_lib "python-novaclient"
651 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 +0100652 fi
Dean Troyerbf67c192012-09-21 15:09:37 -0500653}
654
655# install_nova() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100656function install_nova {
Dean Troyer8c032d12013-09-23 13:53:13 -0500657 if is_service_enabled n-cpu && [[ -r $NOVA_PLUGINS/hypervisor-$VIRT_DRIVER ]]; then
658 install_nova_hypervisor
Dean Troyerbf67c192012-09-21 15:09:37 -0500659 fi
660
Attila Fazekas5a35e732013-10-29 08:23:43 +0100661 if is_service_enabled n-novnc; then
662 # a websockets/html5 or flash powered VNC console for vm instances
Ilya Kharin645171c2013-11-12 12:44:20 +0400663 NOVNC_FROM_PACKAGE=`trueorfalse False $NOVNC_FROM_PACKAGE`
Ben Nemecadd4ca32013-11-08 17:22:51 +0000664 if [ "$NOVNC_FROM_PACKAGE" = "True" ]; then
Attila Fazekas5a35e732013-10-29 08:23:43 +0100665 NOVNC_WEB_DIR=/usr/share/novnc
666 install_package novnc
667 else
668 NOVNC_WEB_DIR=$DEST/noVNC
669 git_clone $NOVNC_REPO $NOVNC_WEB_DIR $NOVNC_BRANCH
670 fi
671 fi
672
673 if is_service_enabled n-spice; then
674 # a websockets/html5 or flash powered SPICE console for vm instances
Ben Nemecadd4ca32013-11-08 17:22:51 +0000675 SPICE_FROM_PACKAGE=`trueorfalse True $SPICE_FROM_PACKAGE`
676 if [ "$SPICE_FROM_PACKAGE" = "True" ]; then
Attila Fazekas5a35e732013-10-29 08:23:43 +0100677 SPICE_WEB_DIR=/usr/share/spice-html5
678 install_package spice-html5
679 else
680 SPICE_WEB_DIR=$DEST/spice-html5
681 git_clone $SPICE_REPO $SPICE_WEB_DIR $SPICE_BRANCH
682 fi
683 fi
684
Dean Troyerbf67c192012-09-21 15:09:37 -0500685 git_clone $NOVA_REPO $NOVA_DIR $NOVA_BRANCH
Dean Troyer253a1a32013-04-01 18:23:22 -0500686 setup_develop $NOVA_DIR
Attila Fazekasfac533e2013-08-14 16:04:01 +0200687 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 -0500688}
689
Dean Troyer3a3a2ba2012-12-11 15:26:24 -0600690# start_nova_api() - Start the API process ahead of other things
Ian Wienandaee18c72014-02-21 15:35:08 +1100691function start_nova_api {
Dean Troyer3a3a2ba2012-12-11 15:26:24 -0600692 # Get right service port for testing
693 local service_port=$NOVA_SERVICE_PORT
Rob Crittenden18d47782014-03-19 17:47:42 -0400694 local service_protocol=$NOVA_SERVICE_PROTOCOL
Dean Troyer3a3a2ba2012-12-11 15:26:24 -0600695 if is_service_enabled tls-proxy; then
696 service_port=$NOVA_SERVICE_PORT_INT
Rob Crittenden18d47782014-03-19 17:47:42 -0400697 service_protocol="http"
Dean Troyer3a3a2ba2012-12-11 15:26:24 -0600698 fi
699
Chris Dent2f27a0e2014-09-09 13:46:02 +0100700 run_process n-api "$NOVA_BIN_DIR/nova-api"
Dean Troyer3a3a2ba2012-12-11 15:26:24 -0600701 echo "Waiting for nova-api to start..."
Rob Crittenden18d47782014-03-19 17:47:42 -0400702 if ! wait_for_service $SERVICE_TIMEOUT $service_protocol://$SERVICE_HOST:$service_port; then
Sean Dague101b4242013-10-22 08:47:11 -0400703 die $LINENO "nova-api did not start"
Dean Troyer3a3a2ba2012-12-11 15:26:24 -0600704 fi
705
706 # Start proxies if enabled
707 if is_service_enabled tls-proxy; then
708 start_tls_proxy '*' $NOVA_SERVICE_PORT $NOVA_SERVICE_HOST $NOVA_SERVICE_PORT_INT &
Rob Crittenden18d47782014-03-19 17:47:42 -0400709 start_tls_proxy '*' $EC2_SERVICE_PORT $NOVA_SERVICE_HOST $EC2_SERVICE_PORT_INT &
Dean Troyer3a3a2ba2012-12-11 15:26:24 -0600710 fi
711}
712
Dan Smith2e159462013-10-21 13:06:11 -0700713# start_nova_compute() - Start the compute process
Ian Wienandaee18c72014-02-21 15:35:08 +1100714function start_nova_compute {
Chris Behrens6db29902013-10-22 09:22:36 -0700715 if is_service_enabled n-cell; then
716 local compute_cell_conf=$NOVA_CELLS_CONF
717 else
718 local compute_cell_conf=$NOVA_CONF
719 fi
Kieran Spearfb2a3ae2013-03-11 23:55:49 +0000720
Bob Ballb1e49bf2013-05-30 16:47:19 +0100721 if [[ "$VIRT_DRIVER" = 'libvirt' ]]; then
722 # The group **$LIBVIRT_GROUP** is added to the current user in this script.
Dean Troyer3324f192014-09-18 09:26:39 -0500723 # ``sg`` is used in run_process to execute nova-compute as a member of the
Chris Dent2f27a0e2014-09-09 13:46:02 +0100724 # **$LIBVIRT_GROUP** group.
725 run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $compute_cell_conf" $LIBVIRT_GROUP
Joe Gordon2c94ee52013-08-02 02:02:01 +0000726 elif [[ "$VIRT_DRIVER" = 'fake' ]]; then
Dean Troyer0038a1a2014-07-25 15:27:54 -0500727 local i
Sean Dague101b4242013-10-22 08:47:11 -0400728 for i in `seq 1 $NUMBER_FAKE_NOVA_COMPUTE`; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100729 # Avoid process redirection of fake host configurations by
730 # creating or modifying real configurations. Each fake
731 # gets its own configuration and own log file.
732 local fake_conf="${NOVA_FAKE_CONF}-${i}"
733 iniset $fake_conf DEFAULT nhost "${HOSTNAME}${i}"
734 run_process "n-cpu-${i}" "$NOVA_BIN_DIR/nova-compute --config-file $compute_cell_conf --config-file $fake_conf"
Sean Dague101b4242013-10-22 08:47:11 -0400735 done
Bob Ballb1e49bf2013-05-30 16:47:19 +0100736 else
Dean Troyer2aa2a892013-08-04 19:53:19 -0500737 if is_service_enabled n-cpu && [[ -r $NOVA_PLUGINS/hypervisor-$VIRT_DRIVER ]]; then
738 start_nova_hypervisor
739 fi
Chris Dent2f27a0e2014-09-09 13:46:02 +0100740 run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $compute_cell_conf"
Bob Ballb1e49bf2013-05-30 16:47:19 +0100741 fi
Dan Smith2e159462013-10-21 13:06:11 -0700742}
743
744# start_nova() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100745function start_nova_rest {
Chris Behrens86199fc2013-10-23 02:54:53 -0700746 local api_cell_conf=$NOVA_CONF
Dan Smith2e159462013-10-21 13:06:11 -0700747 if is_service_enabled n-cell; then
Chris Behrens86199fc2013-10-23 02:54:53 -0700748 local compute_cell_conf=$NOVA_CELLS_CONF
749 else
750 local compute_cell_conf=$NOVA_CONF
Dan Smith2e159462013-10-21 13:06:11 -0700751 fi
752
Chris Dent2f27a0e2014-09-09 13:46:02 +0100753 # ``run_process`` checks ``is_service_enabled``, it is not needed here
754 run_process n-cond "$NOVA_BIN_DIR/nova-conductor --config-file $compute_cell_conf"
755 run_process n-cell-region "$NOVA_BIN_DIR/nova-cells --config-file $api_cell_conf"
756 run_process n-cell-child "$NOVA_BIN_DIR/nova-cells --config-file $compute_cell_conf"
Kieran Spearfb2a3ae2013-03-11 23:55:49 +0000757
Chris Dent2f27a0e2014-09-09 13:46:02 +0100758 run_process n-crt "$NOVA_BIN_DIR/nova-cert --config-file $api_cell_conf"
759 run_process n-net "$NOVA_BIN_DIR/nova-network --config-file $compute_cell_conf"
760 run_process n-sch "$NOVA_BIN_DIR/nova-scheduler --config-file $compute_cell_conf"
761 run_process n-api-meta "$NOVA_BIN_DIR/nova-api-metadata --config-file $compute_cell_conf"
Chris Behrens86199fc2013-10-23 02:54:53 -0700762
Chris Dent2f27a0e2014-09-09 13:46:02 +0100763 run_process n-novnc "$NOVA_BIN_DIR/nova-novncproxy --config-file $api_cell_conf --web $NOVNC_WEB_DIR"
764 run_process n-xvnc "$NOVA_BIN_DIR/nova-xvpvncproxy --config-file $api_cell_conf"
765 run_process n-spice "$NOVA_BIN_DIR/nova-spicehtml5proxy --config-file $api_cell_conf --web $SPICE_WEB_DIR"
766 run_process n-cauth "$NOVA_BIN_DIR/nova-consoleauth --config-file $api_cell_conf"
Dean Troyer1c6c1122013-03-27 17:40:53 -0500767
768 # Starting the nova-objectstore only if swift3 service is not enabled.
769 # Swift will act as s3 objectstore.
770 is_service_enabled swift3 || \
Chris Dent2f27a0e2014-09-09 13:46:02 +0100771 run_process n-obj "$NOVA_BIN_DIR/nova-objectstore --config-file $api_cell_conf"
Dean Troyerbf67c192012-09-21 15:09:37 -0500772}
773
Ian Wienandaee18c72014-02-21 15:35:08 +1100774function start_nova {
Dan Smith2e159462013-10-21 13:06:11 -0700775 start_nova_compute
776 start_nova_rest
777}
778
Joe Gordon767b5a42014-03-12 10:33:15 -0700779function stop_nova_compute {
Adam Gandelmand29ca352014-10-06 14:33:59 -0700780 if [ "$VIRT_DRIVER" == "fake" ]; then
781 local i
782 for i in `seq 1 $NUMBER_FAKE_NOVA_COMPUTE`; do
783 stop_process n-cpu-${i}
784 done
785 else
786 stop_process n-cpu
787 fi
Joe Gordon767b5a42014-03-12 10:33:15 -0700788 if is_service_enabled n-cpu && [[ -r $NOVA_PLUGINS/hypervisor-$VIRT_DRIVER ]]; then
789 stop_nova_hypervisor
790 fi
791}
792
793function stop_nova_rest {
Dean Troyerbf67c192012-09-21 15:09:37 -0500794 # Kill the nova screen windows
Kieran Spearfb2a3ae2013-03-11 23:55:49 +0000795 # Some services are listed here twice since more than one instance
796 # of a service may be running in certain configs.
Joe Gordonbbf759e2014-03-13 18:09:17 -0700797 for serv in n-api n-crt n-net n-sch n-novnc n-xvnc n-cauth n-spice n-cond n-cell n-cell n-api-meta n-obj; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100798 stop_process $serv
Dean Troyerbf67c192012-09-21 15:09:37 -0500799 done
Joe Gordon767b5a42014-03-12 10:33:15 -0700800}
801
802# stop_nova() - Stop running processes (non-screen)
803function stop_nova {
804 stop_nova_rest
805 stop_nova_compute
Dean Troyerbf67c192012-09-21 15:09:37 -0500806}
807
Dean Troyercc6b4432013-04-08 15:38:03 -0500808
Dean Troyerbf67c192012-09-21 15:09:37 -0500809# Restore xtrace
810$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400811
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100812# Tell emacs to use shell-script-mode
813## Local variables:
814## mode: shell-script
815## End: