blob: 04a869e732f4cd6a9dbdc3383136d404630e4e40 [file] [log] [blame]
Dean Troyerbf67c192012-09-21 15:09:37 -05001# lib/nova
2# Functions to control the configuration and operation of the XXXX service
3
4# Dependencies:
5# ``functions`` file
6# ``DEST``, ``DATA_DIR`` must be defined
7# ``SERVICE_{TENANT_NAME|PASSWORD}`` must be defined
8# ``LIBVIRT_TYPE`` must be defined
9# ``INSTANCE_NAME_PREFIX``, ``VOLUME_NAME_PREFIX`` must be defined
Dean Troyerbc071bc2012-10-01 14:06:44 -050010# ``KEYSTONE_TOKEN_FORMAT`` must be defined
Dean Troyerbf67c192012-09-21 15:09:37 -050011
12# ``stack.sh`` calls the entry points in this order:
13#
14# install_nova
15# configure_nova
Dean Troyerda7b8092012-10-08 18:12:14 -050016# create_nova_conf
Dean Troyerbf67c192012-09-21 15:09:37 -050017# init_nova
18# start_nova
19# stop_nova
20# cleanup_nova
21
22# Save trace setting
23XTRACE=$(set +o | grep xtrace)
24set +o xtrace
25
26
27# Defaults
28# --------
29
30# Set up default directories
31NOVA_DIR=$DEST/nova
32NOVACLIENT_DIR=$DEST/python-novaclient
33NOVA_STATE_PATH=${NOVA_STATE_PATH:=$DATA_DIR/nova}
34# INSTANCES_PATH is the previous name for this
35NOVA_INSTANCES_PATH=${NOVA_INSTANCES_PATH:=${INSTANCES_PATH:=$NOVA_STATE_PATH/instances}}
Dean Troyerbc071bc2012-10-01 14:06:44 -050036NOVA_AUTH_CACHE_DIR=${NOVA_AUTH_CACHE_DIR:-/var/cache/nova}
Dean Troyerbf67c192012-09-21 15:09:37 -050037
38NOVA_CONF_DIR=/etc/nova
39NOVA_CONF=$NOVA_CONF_DIR/nova.conf
40NOVA_API_PASTE_INI=${NOVA_API_PASTE_INI:-$NOVA_CONF_DIR/api-paste.ini}
41
Dean Troyer3a3a2ba2012-12-11 15:26:24 -060042# Public facing bits
43NOVA_SERVICE_HOST=${NOVA_SERVICE_HOST:-$SERVICE_HOST}
44NOVA_SERVICE_PORT=${NOVA_SERVICE_PORT:-8774}
45NOVA_SERVICE_PORT_INT=${NOVA_SERVICE_PORT_INT:-18774}
46NOVA_SERVICE_PROTOCOL=${NOVA_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
47
Dean Troyerbf67c192012-09-21 15:09:37 -050048# Support entry points installation of console scripts
49if [[ -d $NOVA_DIR/bin ]]; then
50 NOVA_BIN_DIR=$NOVA_DIR/bin
51else
52 NOVA_BIN_DIR=/usr/local/bin
53fi
54
55# Set the paths of certain binaries
Vincent Untz856a11e2012-11-21 16:04:12 +010056NOVA_ROOTWRAP=$(get_rootwrap_location nova)
Dean Troyerbf67c192012-09-21 15:09:37 -050057
58# Allow rate limiting to be turned off for testing, like for Tempest
59# NOTE: Set API_RATE_LIMIT="False" to turn OFF rate limiting
60API_RATE_LIMIT=${API_RATE_LIMIT:-"True"}
61
62# Nova supports pluggable schedulers. The default ``FilterScheduler``
63# should work in most cases.
64SCHEDULER=${SCHEDULER:-nova.scheduler.filter_scheduler.FilterScheduler}
65
66QEMU_CONF=/etc/libvirt/qemu.conf
67
68
69# Entry Points
70# ------------
71
72function add_nova_opt {
73 echo "$1" >>$NOVA_CONF
74}
75
76# Helper to clean iptables rules
77function clean_iptables() {
78 # Delete rules
79 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
80 # Delete nat rules
81 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
82 # Delete chains
83 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
84 # Delete nat chains
85 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
86}
87
88# cleanup_nova() - Remove residual data files, anything left over from previous
89# runs that a clean run would need to clean up
90function cleanup_nova() {
91 if is_service_enabled n-cpu; then
92 # Clean iptables from previous runs
93 clean_iptables
94
95 # Destroy old instances
96 instances=`sudo virsh list --all | grep $INSTANCE_NAME_PREFIX | sed "s/.*\($INSTANCE_NAME_PREFIX[0-9a-fA-F]*\).*/\1/g"`
97 if [ ! "$instances" = "" ]; then
98 echo $instances | xargs -n1 sudo virsh destroy || true
99 echo $instances | xargs -n1 sudo virsh undefine || true
100 fi
101
102 # Logout and delete iscsi sessions
103 sudo iscsiadm --mode node | grep $VOLUME_NAME_PREFIX | cut -d " " -f2 | xargs sudo iscsiadm --mode node --logout || true
104 sudo iscsiadm --mode node | grep $VOLUME_NAME_PREFIX | cut -d " " -f2 | sudo iscsiadm --mode node --op delete || true
105
106 # Clean out the instances directory.
107 sudo rm -rf $NOVA_INSTANCES_PATH/*
108 fi
109}
110
111# configure_novaclient() - Set config files, create data dirs, etc
112function configure_novaclient() {
113 setup_develop $NOVACLIENT_DIR
114}
115
116# configure_nova_rootwrap() - configure Nova's rootwrap
117function configure_nova_rootwrap() {
118 # Deploy new rootwrap filters files (owned by root).
119 # Wipe any existing rootwrap.d files first
120 if [[ -d $NOVA_CONF_DIR/rootwrap.d ]]; then
121 sudo rm -rf $NOVA_CONF_DIR/rootwrap.d
122 fi
123 # Deploy filters to /etc/nova/rootwrap.d
124 sudo mkdir -m 755 $NOVA_CONF_DIR/rootwrap.d
125 sudo cp $NOVA_DIR/etc/nova/rootwrap.d/*.filters $NOVA_CONF_DIR/rootwrap.d
126 sudo chown -R root:root $NOVA_CONF_DIR/rootwrap.d
127 sudo chmod 644 $NOVA_CONF_DIR/rootwrap.d/*
128 # Set up rootwrap.conf, pointing to /etc/nova/rootwrap.d
129 sudo cp $NOVA_DIR/etc/nova/rootwrap.conf $NOVA_CONF_DIR/
130 sudo sed -e "s:^filters_path=.*$:filters_path=$NOVA_CONF_DIR/rootwrap.d:" -i $NOVA_CONF_DIR/rootwrap.conf
131 sudo chown root:root $NOVA_CONF_DIR/rootwrap.conf
132 sudo chmod 0644 $NOVA_CONF_DIR/rootwrap.conf
133 # Specify rootwrap.conf as first parameter to nova-rootwrap
134 ROOTWRAP_SUDOER_CMD="$NOVA_ROOTWRAP $NOVA_CONF_DIR/rootwrap.conf *"
135
136 # Set up the rootwrap sudoers for nova
137 TEMPFILE=`mktemp`
138 echo "$USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
139 chmod 0440 $TEMPFILE
140 sudo chown root:root $TEMPFILE
141 sudo mv $TEMPFILE /etc/sudoers.d/nova-rootwrap
142}
143
144# configure_nova() - Set config files, create data dirs, etc
145function configure_nova() {
146 setup_develop $NOVA_DIR
147
148 # Put config files in ``/etc/nova`` for everyone to find
149 if [[ ! -d $NOVA_CONF_DIR ]]; then
150 sudo mkdir -p $NOVA_CONF_DIR
151 fi
152 sudo chown `whoami` $NOVA_CONF_DIR
153
154 cp -p $NOVA_DIR/etc/nova/policy.json $NOVA_CONF_DIR
155
156 configure_nova_rootwrap
157
158 if is_service_enabled n-api; then
159 # Use the sample http middleware configuration supplied in the
160 # Nova sources. This paste config adds the configuration required
161 # for Nova to validate Keystone tokens.
162
163 # Remove legacy paste config if present
164 rm -f $NOVA_DIR/bin/nova-api-paste.ini
165
166 # Get the sample configuration file in place
167 cp $NOVA_DIR/etc/nova/api-paste.ini $NOVA_CONF_DIR
168
169 # Rewrite the authtoken configuration for our Keystone service.
170 # This is a bit defensive to allow the sample file some variance.
171 sed -e "
172 /^admin_token/i admin_tenant_name = $SERVICE_TENANT_NAME
173 /admin_tenant_name/s/^.*$/admin_tenant_name = $SERVICE_TENANT_NAME/;
174 /admin_user/s/^.*$/admin_user = nova/;
175 /admin_password/s/^.*$/admin_password = $SERVICE_PASSWORD/;
176 s,%SERVICE_TENANT_NAME%,$SERVICE_TENANT_NAME,g;
177 s,%SERVICE_TOKEN%,$SERVICE_TOKEN,g;
178 " -i $NOVA_API_PASTE_INI
Dean Troyer3a3a2ba2012-12-11 15:26:24 -0600179 iniset $NOVA_API_PASTE_INI filter:authtoken auth_host $SERVICE_HOST
180 if is_service_enabled tls-proxy; then
181 iniset $NOVA_API_PASTE_INI filter:authtoken auth_protocol $SERVICE_PROTOCOL
182 fi
Dean Troyerbf67c192012-09-21 15:09:37 -0500183 fi
184
Akihiro MOTOKI5e3deb62012-12-11 17:09:02 +0900185 iniset $NOVA_API_PASTE_INI filter:authtoken signing_dir $NOVA_AUTH_CACHE_DIR
Dean Troyerbc071bc2012-10-01 14:06:44 -0500186
Dean Troyerbf67c192012-09-21 15:09:37 -0500187 if is_service_enabled n-cpu; then
188 # Force IP forwarding on, just on case
189 sudo sysctl -w net.ipv4.ip_forward=1
190
191 # Attempt to load modules: network block device - used to manage qcow images
192 sudo modprobe nbd || true
193
194 # Check for kvm (hardware based virtualization). If unable to initialize
195 # kvm, we drop back to the slower emulation mode (qemu). Note: many systems
196 # come with hardware virtualization disabled in BIOS.
197 if [[ "$LIBVIRT_TYPE" == "kvm" ]]; then
198 sudo modprobe kvm || true
199 if [ ! -e /dev/kvm ]; then
200 echo "WARNING: Switching to QEMU"
201 LIBVIRT_TYPE=qemu
202 if which selinuxenabled 2>&1 > /dev/null && selinuxenabled; then
203 # https://bugzilla.redhat.com/show_bug.cgi?id=753589
204 sudo setsebool virt_use_execmem on
205 fi
206 fi
207 fi
208
209 # Install and configure **LXC** if specified. LXC is another approach to
210 # splitting a system into many smaller parts. LXC uses cgroups and chroot
211 # to simulate multiple systems.
212 if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then
Vincent Untzc18b9652012-12-04 12:36:34 +0100213 if is_ubuntu; then
Dean Troyerbf67c192012-09-21 15:09:37 -0500214 if [[ ! "$DISTRO" > natty ]]; then
215 cgline="none /cgroup cgroup cpuacct,memory,devices,cpu,freezer,blkio 0 0"
216 sudo mkdir -p /cgroup
217 if ! grep -q cgroup /etc/fstab; then
218 echo "$cgline" | sudo tee -a /etc/fstab
219 fi
220 if ! mount -n | grep -q cgroup; then
221 sudo mount /cgroup
222 fi
223 fi
224 fi
225 fi
226
Yoshihiro Kaneko602cf9b2012-07-23 06:27:36 +0000227 if is_service_enabled quantum && is_quantum_ovs_base_plugin "$Q_PLUGIN" && ! sudo grep -q '^cgroup_device_acl' $QEMU_CONF ; then
Dean Troyerbf67c192012-09-21 15:09:37 -0500228 # Add /dev/net/tun to cgroup_device_acls, needed for type=ethernet interfaces
229 cat <<EOF | sudo tee -a $QEMU_CONF
230cgroup_device_acl = [
231 "/dev/null", "/dev/full", "/dev/zero",
232 "/dev/random", "/dev/urandom",
233 "/dev/ptmx", "/dev/kvm", "/dev/kqemu",
234 "/dev/rtc", "/dev/hpet","/dev/net/tun",
235]
236EOF
237 fi
238
Vincent Untzc18b9652012-12-04 12:36:34 +0100239 if is_ubuntu; then
Dean Troyerbf67c192012-09-21 15:09:37 -0500240 LIBVIRT_DAEMON=libvirt-bin
241 else
Vincent Untzf1c094c2012-12-05 17:59:04 +0100242 LIBVIRT_DAEMON=libvirtd
243 fi
244
245 # For distributions using polkit to authorize access to libvirt,
246 # configure polkit accordingly.
247 # Based on http://wiki.libvirt.org/page/SSHPolicyKitSetup
248 if is_fedora; then
Dean Troyerbf67c192012-09-21 15:09:37 -0500249 sudo bash -c 'cat <<EOF >/etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
250[libvirt Management Access]
251Identity=unix-group:libvirtd
252Action=org.libvirt.unix.manage
253ResultAny=yes
254ResultInactive=yes
255ResultActive=yes
256EOF'
Vincent Untzf1c094c2012-12-05 17:59:04 +0100257 elif is_suse; then
258 # Work around the fact that polkit-default-privs overrules pklas
259 # with 'unix-group:$group'.
260 sudo bash -c "cat <<EOF >/etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
261[libvirt Management Access]
262Identity=unix-user:$USER
263Action=org.libvirt.unix.manage
264ResultAny=yes
265ResultInactive=yes
266ResultActive=yes
267EOF"
Dean Troyerbf67c192012-09-21 15:09:37 -0500268 fi
269
270 # The user that nova runs as needs to be member of **libvirtd** group otherwise
271 # nova-compute will be unable to use libvirt.
Vincent Untzf1c094c2012-12-05 17:59:04 +0100272 if ! getent group libvirtd >/dev/null; then
273 sudo groupadd libvirtd
274 fi
Vincent Untz856a11e2012-11-21 16:04:12 +0100275 add_user_to_group `whoami` libvirtd
Dean Troyerbf67c192012-09-21 15:09:37 -0500276
277 # libvirt detects various settings on startup, as we potentially changed
278 # the system configuration (modules, filesystems), we need to restart
279 # libvirt to detect those changes.
280 restart_service $LIBVIRT_DAEMON
281
282
283 # Instance Storage
284 # ----------------
285
286 # Nova stores each instance in its own directory.
287 mkdir -p $NOVA_INSTANCES_PATH
288
289 # You can specify a different disk to be mounted and used for backing the
290 # virtual machines. If there is a partition labeled nova-instances we
291 # mount it (ext filesystems can be labeled via e2label).
292 if [ -L /dev/disk/by-label/nova-instances ]; then
293 if ! mount -n | grep -q $NOVA_INSTANCES_PATH; then
294 sudo mount -L nova-instances $NOVA_INSTANCES_PATH
295 sudo chown -R `whoami` $NOVA_INSTANCES_PATH
296 fi
297 fi
298
299 # Clean up old instances
300 cleanup_nova
301 fi
302}
303
Dean Troyera0dce262012-12-11 16:52:37 -0600304# create_nova_accounts() - Set up common required nova accounts
305
306# Tenant User Roles
307# ------------------------------------------------------------------
308# service nova admin, [ResellerAdmin (swift only)]
309
310# Migrated from keystone_data.sh
311create_nova_accounts() {
312
313 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
314 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
315
316 # Nova
317 if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
318 NOVA_USER=$(keystone user-create \
319 --name=nova \
320 --pass="$SERVICE_PASSWORD" \
321 --tenant_id $SERVICE_TENANT \
322 --email=nova@example.com \
323 | grep " id " | get_field 2)
324 keystone user-role-add \
325 --tenant_id $SERVICE_TENANT \
326 --user_id $NOVA_USER \
327 --role_id $ADMIN_ROLE
328 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
329 NOVA_SERVICE=$(keystone service-create \
330 --name=nova \
331 --type=compute \
332 --description="Nova Compute Service" \
333 | grep " id " | get_field 2)
334 keystone endpoint-create \
335 --region RegionOne \
336 --service_id $NOVA_SERVICE \
Dean Troyer3a3a2ba2012-12-11 15:26:24 -0600337 --publicurl "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2/\$(tenant_id)s" \
338 --adminurl "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2/\$(tenant_id)s" \
339 --internalurl "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2/\$(tenant_id)s"
Dean Troyera0dce262012-12-11 16:52:37 -0600340 fi
341 fi
342}
343
Dean Troyerda7b8092012-10-08 18:12:14 -0500344# create_nova_conf() - Create a new nova.conf file
345function create_nova_conf() {
Dean Troyerbf67c192012-09-21 15:09:37 -0500346 # Remove legacy ``nova.conf``
347 rm -f $NOVA_DIR/bin/nova.conf
348
349 # (Re)create ``nova.conf``
Dean Troyer3cf1ffb2012-10-02 11:51:27 -0500350 rm -f $NOVA_CONF
Dean Troyerbf67c192012-09-21 15:09:37 -0500351 add_nova_opt "[DEFAULT]"
352 add_nova_opt "verbose=True"
353 add_nova_opt "auth_strategy=keystone"
354 add_nova_opt "allow_resize_to_same_host=True"
355 add_nova_opt "api_paste_config=$NOVA_API_PASTE_INI"
356 add_nova_opt "rootwrap_config=$NOVA_CONF_DIR/rootwrap.conf"
357 add_nova_opt "compute_scheduler_driver=$SCHEDULER"
Dean Troyer3cf1ffb2012-10-02 11:51:27 -0500358 add_nova_opt "dhcpbridge_flagfile=$NOVA_CONF"
Dean Troyerbf67c192012-09-21 15:09:37 -0500359 add_nova_opt "force_dhcp_release=True"
360 add_nova_opt "fixed_range=$FIXED_RANGE"
361 add_nova_opt "s3_host=$SERVICE_HOST"
362 add_nova_opt "s3_port=$S3_SERVICE_PORT"
363 add_nova_opt "osapi_compute_extension=nova.api.openstack.compute.contrib.standard_extensions"
364 add_nova_opt "my_ip=$HOST_IP"
Terry Wilson428af5a2012-11-01 16:12:39 -0400365 local dburl
366 database_connection_url dburl nova
367 add_nova_opt "sql_connection=$dburl"
Dean Troyerbf67c192012-09-21 15:09:37 -0500368 add_nova_opt "libvirt_type=$LIBVIRT_TYPE"
369 add_nova_opt "libvirt_cpu_mode=none"
370 add_nova_opt "instance_name_template=${INSTANCE_NAME_PREFIX}%08x"
Dean Troyerbf67c192012-09-21 15:09:37 -0500371
372 if is_service_enabled n-api; then
373 add_nova_opt "enabled_apis=$NOVA_ENABLED_APIS"
Dean Troyer3a3a2ba2012-12-11 15:26:24 -0600374 if is_service_enabled tls-proxy; then
375 # Set the service port for a proxy to take the original
376 add_nova_opt "osapi_compute_listen_port=$NOVA_SERVICE_PORT_INT"
377 fi
Dean Troyerbf67c192012-09-21 15:09:37 -0500378 fi
Dean Troyerbf67c192012-09-21 15:09:37 -0500379 if is_service_enabled cinder; then
380 add_nova_opt "volume_api_class=nova.volume.cinder.API"
381 fi
382 if [ -n "$NOVA_STATE_PATH" ]; then
383 add_nova_opt "state_path=$NOVA_STATE_PATH"
Dean Troyer13314452012-10-23 15:09:50 -0500384 add_nova_opt "lock_path=$NOVA_STATE_PATH"
Dean Troyerbf67c192012-09-21 15:09:37 -0500385 fi
386 if [ -n "$NOVA_INSTANCES_PATH" ]; then
387 add_nova_opt "instances_path=$NOVA_INSTANCES_PATH"
388 fi
389 if [ "$MULTI_HOST" != "False" ]; then
390 add_nova_opt "multi_host=True"
391 add_nova_opt "send_arp_for_ha=True"
392 fi
393 if [ "$SYSLOG" != "False" ]; then
394 add_nova_opt "use_syslog=True"
395 fi
396 if [ "$API_RATE_LIMIT" != "True" ]; then
397 add_nova_opt "api_rate_limit=False"
398 fi
399 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
400 # Add color to logging output
401 add_nova_opt "logging_context_format_string=%(asctime)s %(color)s%(levelname)s %(name)s [%(request_id)s %(user_name)s %(project_name)s%(color)s] %(instance)s%(color)s%(message)s"
402 add_nova_opt "logging_default_format_string=%(asctime)s %(color)s%(levelname)s %(name)s [-%(color)s] %(instance)s%(color)s%(message)s"
403 add_nova_opt "logging_debug_format_suffix=from (pid=%(process)d) %(funcName)s %(pathname)s:%(lineno)d"
404 add_nova_opt "logging_exception_prefix=%(color)s%(asctime)s TRACE %(name)s %(instance)s"
405 else
406 # Show user_name and project_name instead of user_id and project_id
407 add_nova_opt "logging_context_format_string=%(asctime)s %(levelname)s %(name)s [%(request_id)s %(user_name)s %(project_name)s] %(instance)s%(message)s"
408 fi
Eoghan Glynn1fcc6a12012-10-25 14:57:14 +0000409 if is_service_enabled ceilometer; then
410 add_nova_opt "instance_usage_audit=True"
411 add_nova_opt "instance_usage_audit_period=hour"
412 add_nova_opt "notification_driver=nova.openstack.common.notifier.rabbit_notifier"
413 add_nova_opt "notification_driver=ceilometer.compute.nova_notifier"
414 fi
415
Dean Troyerbf67c192012-09-21 15:09:37 -0500416
417 # Provide some transition from ``EXTRA_FLAGS`` to ``EXTRA_OPTS``
418 if [[ -z "$EXTRA_OPTS" && -n "$EXTRA_FLAGS" ]]; then
419 EXTRA_OPTS=$EXTRA_FLAGS
420 fi
421
422 # Define extra nova conf flags by defining the array ``EXTRA_OPTS``.
423 # For Example: ``EXTRA_OPTS=(foo=true bar=2)``
424 for I in "${EXTRA_OPTS[@]}"; do
425 # Attempt to convert flags to options
426 add_nova_opt ${I//--}
427 done
Dean Troyerda7b8092012-10-08 18:12:14 -0500428}
Dean Troyerbf67c192012-09-21 15:09:37 -0500429
Dean Troyerda7b8092012-10-08 18:12:14 -0500430# init_nova() - Initialize databases, etc.
431function init_nova() {
Dean Troyerbf67c192012-09-21 15:09:37 -0500432 # Nova Database
433 # -------------
434
435 # All nova components talk to a central database. We will need to do this step
436 # only once for an entire cluster.
437
Terry Wilson428af5a2012-11-01 16:12:39 -0400438 if is_service_enabled $DATABASE_BACKENDS && is_service_enabled nova; then
Dean Troyerbf67c192012-09-21 15:09:37 -0500439 # (Re)create nova database
Dean Troyerbf67c192012-09-21 15:09:37 -0500440 # Explicitly use latin1: to avoid lp#829209, nova expects the database to
441 # use latin1 by default, and then upgrades the database to utf8 (see the
442 # 082_essex.py in nova)
Terry Wilson428af5a2012-11-01 16:12:39 -0400443 recreate_database nova latin1
Dean Troyerbf67c192012-09-21 15:09:37 -0500444
445 # (Re)create nova database
446 $NOVA_BIN_DIR/nova-manage db sync
447 fi
448
Akihiro MOTOKI5e3deb62012-12-11 17:09:02 +0900449 # Create cache dir
450 sudo mkdir -p $NOVA_AUTH_CACHE_DIR
451 sudo chown `whoami` $NOVA_AUTH_CACHE_DIR
Dean Troyerbf67c192012-09-21 15:09:37 -0500452}
453
454# install_novaclient() - Collect source and prepare
455function install_novaclient() {
456 git_clone $NOVACLIENT_REPO $NOVACLIENT_DIR $NOVACLIENT_BRANCH
457}
458
459# install_nova() - Collect source and prepare
460function install_nova() {
461 if is_service_enabled n-cpu; then
Vincent Untzc18b9652012-12-04 12:36:34 +0100462 if is_ubuntu; then
Vincent Untz00011c02012-12-06 09:56:32 +0100463 install_package libvirt-bin
464 elif is_fedora || is_suse; then
465 install_package libvirt
Dean Troyerbf67c192012-09-21 15:09:37 -0500466 else
Vincent Untz00011c02012-12-06 09:56:32 +0100467 exit_distro_not_supported "libvirt installation"
Dean Troyerbf67c192012-09-21 15:09:37 -0500468 fi
Vincent Untz00011c02012-12-06 09:56:32 +0100469
Dean Troyerbf67c192012-09-21 15:09:37 -0500470 # Install and configure **LXC** if specified. LXC is another approach to
471 # splitting a system into many smaller parts. LXC uses cgroups and chroot
472 # to simulate multiple systems.
473 if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then
Vincent Untzc18b9652012-12-04 12:36:34 +0100474 if is_ubuntu; then
Dean Troyerbf67c192012-09-21 15:09:37 -0500475 if [[ "$DISTRO" > natty ]]; then
476 install_package cgroup-lite
477 fi
478 else
479 ### FIXME(dtroyer): figure this out
480 echo "RPM-based cgroup not implemented yet"
481 yum_install libcgroup-tools
482 fi
483 fi
484 fi
485
486 git_clone $NOVA_REPO $NOVA_DIR $NOVA_BRANCH
487}
488
Dean Troyer3a3a2ba2012-12-11 15:26:24 -0600489# start_nova_api() - Start the API process ahead of other things
490function start_nova_api() {
491 # Get right service port for testing
492 local service_port=$NOVA_SERVICE_PORT
493 if is_service_enabled tls-proxy; then
494 service_port=$NOVA_SERVICE_PORT_INT
495 fi
496
497 screen_it n-api "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-api"
498 echo "Waiting for nova-api to start..."
499 if ! wait_for_service $SERVICE_TIMEOUT http://$SERVICE_HOST:$service_port; then
500 echo "nova-api did not start"
501 exit 1
502 fi
503
504 # Start proxies if enabled
505 if is_service_enabled tls-proxy; then
506 start_tls_proxy '*' $NOVA_SERVICE_PORT $NOVA_SERVICE_HOST $NOVA_SERVICE_PORT_INT &
507 fi
508}
509
Dean Troyerbf67c192012-09-21 15:09:37 -0500510# start_nova() - Start running processes, including screen
511function start_nova() {
512 # The group **libvirtd** is added to the current user in this script.
513 # Use 'sg' to execute nova-compute as a member of the **libvirtd** group.
514 # ``screen_it`` checks ``is_service_enabled``, it is not needed here
Russell Bryantff7f3082012-11-29 22:00:51 -0500515 screen_it n-cond "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-conductor"
Dean Troyerbf67c192012-09-21 15:09:37 -0500516 screen_it n-cpu "cd $NOVA_DIR && sg libvirtd $NOVA_BIN_DIR/nova-compute"
517 screen_it n-crt "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-cert"
518 screen_it n-net "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-network"
519 screen_it n-sch "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-scheduler"
Dean Troyer3cf1ffb2012-10-02 11:51:27 -0500520 screen_it n-novnc "cd $NOVNC_DIR && ./utils/nova-novncproxy --config-file $NOVA_CONF --web ."
Monty Taylor0edfd6f2012-11-23 15:00:38 -0800521 screen_it n-xvnc "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-xvpvncproxy --config-file $NOVA_CONF"
522 screen_it n-cauth "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-consoleauth"
Dean Troyerbf67c192012-09-21 15:09:37 -0500523}
524
525# stop_nova() - Stop running processes (non-screen)
526function stop_nova() {
527 # Kill the nova screen windows
Dan Smithd57ccf02012-11-15 10:09:33 -0800528 for serv in n-api n-cpu n-crt n-net n-sch n-novnc n-xvnc n-cauth n-cond; do
Dean Troyerbf67c192012-09-21 15:09:37 -0500529 screen -S $SCREEN_NAME -p $serv -X kill
530 done
531}
532
533# Restore xtrace
534$XTRACE