blob: 8074153383b6b24c23b66e8f4c6aa1333590b524 [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
42# Support entry points installation of console scripts
43if [[ -d $NOVA_DIR/bin ]]; then
44 NOVA_BIN_DIR=$NOVA_DIR/bin
45else
46 NOVA_BIN_DIR=/usr/local/bin
47fi
48
49# Set the paths of certain binaries
Vincent Untz856a11e2012-11-21 16:04:12 +010050NOVA_ROOTWRAP=$(get_rootwrap_location nova)
Dean Troyerbf67c192012-09-21 15:09:37 -050051
52# Allow rate limiting to be turned off for testing, like for Tempest
53# NOTE: Set API_RATE_LIMIT="False" to turn OFF rate limiting
54API_RATE_LIMIT=${API_RATE_LIMIT:-"True"}
55
56# Nova supports pluggable schedulers. The default ``FilterScheduler``
57# should work in most cases.
58SCHEDULER=${SCHEDULER:-nova.scheduler.filter_scheduler.FilterScheduler}
59
60QEMU_CONF=/etc/libvirt/qemu.conf
61
62
63# Entry Points
64# ------------
65
66function add_nova_opt {
67 echo "$1" >>$NOVA_CONF
68}
69
70# Helper to clean iptables rules
71function clean_iptables() {
72 # Delete rules
73 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
74 # Delete nat rules
75 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
76 # Delete chains
77 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
78 # Delete nat chains
79 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
80}
81
82# cleanup_nova() - Remove residual data files, anything left over from previous
83# runs that a clean run would need to clean up
84function cleanup_nova() {
85 if is_service_enabled n-cpu; then
86 # Clean iptables from previous runs
87 clean_iptables
88
89 # Destroy old instances
90 instances=`sudo virsh list --all | grep $INSTANCE_NAME_PREFIX | sed "s/.*\($INSTANCE_NAME_PREFIX[0-9a-fA-F]*\).*/\1/g"`
91 if [ ! "$instances" = "" ]; then
92 echo $instances | xargs -n1 sudo virsh destroy || true
93 echo $instances | xargs -n1 sudo virsh undefine || true
94 fi
95
96 # Logout and delete iscsi sessions
97 sudo iscsiadm --mode node | grep $VOLUME_NAME_PREFIX | cut -d " " -f2 | xargs sudo iscsiadm --mode node --logout || true
98 sudo iscsiadm --mode node | grep $VOLUME_NAME_PREFIX | cut -d " " -f2 | sudo iscsiadm --mode node --op delete || true
99
100 # Clean out the instances directory.
101 sudo rm -rf $NOVA_INSTANCES_PATH/*
102 fi
103}
104
105# configure_novaclient() - Set config files, create data dirs, etc
106function configure_novaclient() {
107 setup_develop $NOVACLIENT_DIR
108}
109
110# configure_nova_rootwrap() - configure Nova's rootwrap
111function configure_nova_rootwrap() {
112 # Deploy new rootwrap filters files (owned by root).
113 # Wipe any existing rootwrap.d files first
114 if [[ -d $NOVA_CONF_DIR/rootwrap.d ]]; then
115 sudo rm -rf $NOVA_CONF_DIR/rootwrap.d
116 fi
117 # Deploy filters to /etc/nova/rootwrap.d
118 sudo mkdir -m 755 $NOVA_CONF_DIR/rootwrap.d
119 sudo cp $NOVA_DIR/etc/nova/rootwrap.d/*.filters $NOVA_CONF_DIR/rootwrap.d
120 sudo chown -R root:root $NOVA_CONF_DIR/rootwrap.d
121 sudo chmod 644 $NOVA_CONF_DIR/rootwrap.d/*
122 # Set up rootwrap.conf, pointing to /etc/nova/rootwrap.d
123 sudo cp $NOVA_DIR/etc/nova/rootwrap.conf $NOVA_CONF_DIR/
124 sudo sed -e "s:^filters_path=.*$:filters_path=$NOVA_CONF_DIR/rootwrap.d:" -i $NOVA_CONF_DIR/rootwrap.conf
125 sudo chown root:root $NOVA_CONF_DIR/rootwrap.conf
126 sudo chmod 0644 $NOVA_CONF_DIR/rootwrap.conf
127 # Specify rootwrap.conf as first parameter to nova-rootwrap
128 ROOTWRAP_SUDOER_CMD="$NOVA_ROOTWRAP $NOVA_CONF_DIR/rootwrap.conf *"
129
130 # Set up the rootwrap sudoers for nova
131 TEMPFILE=`mktemp`
132 echo "$USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
133 chmod 0440 $TEMPFILE
134 sudo chown root:root $TEMPFILE
135 sudo mv $TEMPFILE /etc/sudoers.d/nova-rootwrap
136}
137
138# configure_nova() - Set config files, create data dirs, etc
139function configure_nova() {
140 setup_develop $NOVA_DIR
141
142 # Put config files in ``/etc/nova`` for everyone to find
143 if [[ ! -d $NOVA_CONF_DIR ]]; then
144 sudo mkdir -p $NOVA_CONF_DIR
145 fi
146 sudo chown `whoami` $NOVA_CONF_DIR
147
148 cp -p $NOVA_DIR/etc/nova/policy.json $NOVA_CONF_DIR
149
150 configure_nova_rootwrap
151
152 if is_service_enabled n-api; then
153 # Use the sample http middleware configuration supplied in the
154 # Nova sources. This paste config adds the configuration required
155 # for Nova to validate Keystone tokens.
156
157 # Remove legacy paste config if present
158 rm -f $NOVA_DIR/bin/nova-api-paste.ini
159
160 # Get the sample configuration file in place
161 cp $NOVA_DIR/etc/nova/api-paste.ini $NOVA_CONF_DIR
162
163 # Rewrite the authtoken configuration for our Keystone service.
164 # This is a bit defensive to allow the sample file some variance.
165 sed -e "
166 /^admin_token/i admin_tenant_name = $SERVICE_TENANT_NAME
167 /admin_tenant_name/s/^.*$/admin_tenant_name = $SERVICE_TENANT_NAME/;
168 /admin_user/s/^.*$/admin_user = nova/;
169 /admin_password/s/^.*$/admin_password = $SERVICE_PASSWORD/;
170 s,%SERVICE_TENANT_NAME%,$SERVICE_TENANT_NAME,g;
171 s,%SERVICE_TOKEN%,$SERVICE_TOKEN,g;
172 " -i $NOVA_API_PASTE_INI
173 fi
174
Akihiro MOTOKI5e3deb62012-12-11 17:09:02 +0900175 iniset $NOVA_API_PASTE_INI filter:authtoken signing_dir $NOVA_AUTH_CACHE_DIR
Dean Troyerbc071bc2012-10-01 14:06:44 -0500176
Dean Troyerbf67c192012-09-21 15:09:37 -0500177 if is_service_enabled n-cpu; then
178 # Force IP forwarding on, just on case
179 sudo sysctl -w net.ipv4.ip_forward=1
180
181 # Attempt to load modules: network block device - used to manage qcow images
182 sudo modprobe nbd || true
183
184 # Check for kvm (hardware based virtualization). If unable to initialize
185 # kvm, we drop back to the slower emulation mode (qemu). Note: many systems
186 # come with hardware virtualization disabled in BIOS.
187 if [[ "$LIBVIRT_TYPE" == "kvm" ]]; then
188 sudo modprobe kvm || true
189 if [ ! -e /dev/kvm ]; then
190 echo "WARNING: Switching to QEMU"
191 LIBVIRT_TYPE=qemu
192 if which selinuxenabled 2>&1 > /dev/null && selinuxenabled; then
193 # https://bugzilla.redhat.com/show_bug.cgi?id=753589
194 sudo setsebool virt_use_execmem on
195 fi
196 fi
197 fi
198
199 # Install and configure **LXC** if specified. LXC is another approach to
200 # splitting a system into many smaller parts. LXC uses cgroups and chroot
201 # to simulate multiple systems.
202 if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then
Vincent Untzc18b9652012-12-04 12:36:34 +0100203 if is_ubuntu; then
Dean Troyerbf67c192012-09-21 15:09:37 -0500204 if [[ ! "$DISTRO" > natty ]]; then
205 cgline="none /cgroup cgroup cpuacct,memory,devices,cpu,freezer,blkio 0 0"
206 sudo mkdir -p /cgroup
207 if ! grep -q cgroup /etc/fstab; then
208 echo "$cgline" | sudo tee -a /etc/fstab
209 fi
210 if ! mount -n | grep -q cgroup; then
211 sudo mount /cgroup
212 fi
213 fi
214 fi
215 fi
216
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800217 # Prepare directories and packages for baremetal driver
218 if is_baremetal; then
219 configure_baremetal_nova_dirs
220 fi
221
Yoshihiro Kaneko602cf9b2012-07-23 06:27:36 +0000222 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 -0500223 # Add /dev/net/tun to cgroup_device_acls, needed for type=ethernet interfaces
224 cat <<EOF | sudo tee -a $QEMU_CONF
225cgroup_device_acl = [
226 "/dev/null", "/dev/full", "/dev/zero",
227 "/dev/random", "/dev/urandom",
228 "/dev/ptmx", "/dev/kvm", "/dev/kqemu",
229 "/dev/rtc", "/dev/hpet","/dev/net/tun",
230]
231EOF
232 fi
233
Vincent Untzc18b9652012-12-04 12:36:34 +0100234 if is_ubuntu; then
Dean Troyerbf67c192012-09-21 15:09:37 -0500235 LIBVIRT_DAEMON=libvirt-bin
236 else
Vincent Untzf1c094c2012-12-05 17:59:04 +0100237 LIBVIRT_DAEMON=libvirtd
238 fi
239
240 # For distributions using polkit to authorize access to libvirt,
241 # configure polkit accordingly.
242 # Based on http://wiki.libvirt.org/page/SSHPolicyKitSetup
243 if is_fedora; then
Dean Troyerbf67c192012-09-21 15:09:37 -0500244 sudo bash -c 'cat <<EOF >/etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
245[libvirt Management Access]
246Identity=unix-group:libvirtd
247Action=org.libvirt.unix.manage
248ResultAny=yes
249ResultInactive=yes
250ResultActive=yes
251EOF'
Vincent Untzf1c094c2012-12-05 17:59:04 +0100252 elif is_suse; then
253 # Work around the fact that polkit-default-privs overrules pklas
254 # with 'unix-group:$group'.
255 sudo bash -c "cat <<EOF >/etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
256[libvirt Management Access]
257Identity=unix-user:$USER
258Action=org.libvirt.unix.manage
259ResultAny=yes
260ResultInactive=yes
261ResultActive=yes
262EOF"
Dean Troyerbf67c192012-09-21 15:09:37 -0500263 fi
264
265 # The user that nova runs as needs to be member of **libvirtd** group otherwise
266 # nova-compute will be unable to use libvirt.
Vincent Untzf1c094c2012-12-05 17:59:04 +0100267 if ! getent group libvirtd >/dev/null; then
268 sudo groupadd libvirtd
269 fi
Vincent Untz856a11e2012-11-21 16:04:12 +0100270 add_user_to_group `whoami` libvirtd
Dean Troyerbf67c192012-09-21 15:09:37 -0500271
272 # libvirt detects various settings on startup, as we potentially changed
273 # the system configuration (modules, filesystems), we need to restart
274 # libvirt to detect those changes.
275 restart_service $LIBVIRT_DAEMON
276
277
278 # Instance Storage
279 # ----------------
280
281 # Nova stores each instance in its own directory.
282 mkdir -p $NOVA_INSTANCES_PATH
283
284 # You can specify a different disk to be mounted and used for backing the
285 # virtual machines. If there is a partition labeled nova-instances we
286 # mount it (ext filesystems can be labeled via e2label).
287 if [ -L /dev/disk/by-label/nova-instances ]; then
288 if ! mount -n | grep -q $NOVA_INSTANCES_PATH; then
289 sudo mount -L nova-instances $NOVA_INSTANCES_PATH
290 sudo chown -R `whoami` $NOVA_INSTANCES_PATH
291 fi
292 fi
293
294 # Clean up old instances
295 cleanup_nova
296 fi
297}
298
Dean Troyera0dce262012-12-11 16:52:37 -0600299# create_nova_accounts() - Set up common required nova accounts
300
301# Tenant User Roles
302# ------------------------------------------------------------------
303# service nova admin, [ResellerAdmin (swift only)]
304
305# Migrated from keystone_data.sh
306create_nova_accounts() {
307
308 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
309 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
310
311 # Nova
312 if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
313 NOVA_USER=$(keystone user-create \
314 --name=nova \
315 --pass="$SERVICE_PASSWORD" \
316 --tenant_id $SERVICE_TENANT \
317 --email=nova@example.com \
318 | grep " id " | get_field 2)
319 keystone user-role-add \
320 --tenant_id $SERVICE_TENANT \
321 --user_id $NOVA_USER \
322 --role_id $ADMIN_ROLE
323 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
324 NOVA_SERVICE=$(keystone service-create \
325 --name=nova \
326 --type=compute \
327 --description="Nova Compute Service" \
328 | grep " id " | get_field 2)
329 keystone endpoint-create \
330 --region RegionOne \
331 --service_id $NOVA_SERVICE \
332 --publicurl "http://$SERVICE_HOST:\$(compute_port)s/v2/\$(tenant_id)s" \
333 --adminurl "http://$SERVICE_HOST:\$(compute_port)s/v2/\$(tenant_id)s" \
334 --internalurl "http://$SERVICE_HOST:\$(compute_port)s/v2/\$(tenant_id)s"
335 fi
336 fi
337}
338
Dean Troyerda7b8092012-10-08 18:12:14 -0500339# create_nova_conf() - Create a new nova.conf file
340function create_nova_conf() {
Dean Troyerbf67c192012-09-21 15:09:37 -0500341 # Remove legacy ``nova.conf``
342 rm -f $NOVA_DIR/bin/nova.conf
343
344 # (Re)create ``nova.conf``
Dean Troyer3cf1ffb2012-10-02 11:51:27 -0500345 rm -f $NOVA_CONF
Dean Troyerbf67c192012-09-21 15:09:37 -0500346 add_nova_opt "[DEFAULT]"
347 add_nova_opt "verbose=True"
348 add_nova_opt "auth_strategy=keystone"
349 add_nova_opt "allow_resize_to_same_host=True"
350 add_nova_opt "api_paste_config=$NOVA_API_PASTE_INI"
351 add_nova_opt "rootwrap_config=$NOVA_CONF_DIR/rootwrap.conf"
352 add_nova_opt "compute_scheduler_driver=$SCHEDULER"
Dean Troyer3cf1ffb2012-10-02 11:51:27 -0500353 add_nova_opt "dhcpbridge_flagfile=$NOVA_CONF"
Dean Troyerbf67c192012-09-21 15:09:37 -0500354 add_nova_opt "force_dhcp_release=True"
355 add_nova_opt "fixed_range=$FIXED_RANGE"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900356 add_nova_opt "default_floating_pool=$PUBLIC_NETWORK_NAME"
Dean Troyerbf67c192012-09-21 15:09:37 -0500357 add_nova_opt "s3_host=$SERVICE_HOST"
358 add_nova_opt "s3_port=$S3_SERVICE_PORT"
359 add_nova_opt "osapi_compute_extension=nova.api.openstack.compute.contrib.standard_extensions"
360 add_nova_opt "my_ip=$HOST_IP"
Terry Wilson428af5a2012-11-01 16:12:39 -0400361 local dburl
362 database_connection_url dburl nova
363 add_nova_opt "sql_connection=$dburl"
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800364 if is_baremetal; then
365 database_connection_url dburl nova_bm
366 add_nova_opt "baremetal_sql_connection=$dburl"
367 fi
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"
374 fi
Dean Troyerbf67c192012-09-21 15:09:37 -0500375 if is_service_enabled cinder; then
376 add_nova_opt "volume_api_class=nova.volume.cinder.API"
377 fi
378 if [ -n "$NOVA_STATE_PATH" ]; then
379 add_nova_opt "state_path=$NOVA_STATE_PATH"
Dean Troyer13314452012-10-23 15:09:50 -0500380 add_nova_opt "lock_path=$NOVA_STATE_PATH"
Dean Troyerbf67c192012-09-21 15:09:37 -0500381 fi
382 if [ -n "$NOVA_INSTANCES_PATH" ]; then
383 add_nova_opt "instances_path=$NOVA_INSTANCES_PATH"
384 fi
385 if [ "$MULTI_HOST" != "False" ]; then
386 add_nova_opt "multi_host=True"
387 add_nova_opt "send_arp_for_ha=True"
388 fi
389 if [ "$SYSLOG" != "False" ]; then
390 add_nova_opt "use_syslog=True"
391 fi
392 if [ "$API_RATE_LIMIT" != "True" ]; then
393 add_nova_opt "api_rate_limit=False"
394 fi
395 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
396 # Add color to logging output
397 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"
398 add_nova_opt "logging_default_format_string=%(asctime)s %(color)s%(levelname)s %(name)s [-%(color)s] %(instance)s%(color)s%(message)s"
399 add_nova_opt "logging_debug_format_suffix=from (pid=%(process)d) %(funcName)s %(pathname)s:%(lineno)d"
400 add_nova_opt "logging_exception_prefix=%(color)s%(asctime)s TRACE %(name)s %(instance)s"
401 else
402 # Show user_name and project_name instead of user_id and project_id
403 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"
404 fi
Eoghan Glynn1fcc6a12012-10-25 14:57:14 +0000405 if is_service_enabled ceilometer; then
406 add_nova_opt "instance_usage_audit=True"
407 add_nova_opt "instance_usage_audit_period=hour"
408 add_nova_opt "notification_driver=nova.openstack.common.notifier.rabbit_notifier"
409 add_nova_opt "notification_driver=ceilometer.compute.nova_notifier"
410 fi
411
Dean Troyerbf67c192012-09-21 15:09:37 -0500412
413 # Provide some transition from ``EXTRA_FLAGS`` to ``EXTRA_OPTS``
414 if [[ -z "$EXTRA_OPTS" && -n "$EXTRA_FLAGS" ]]; then
415 EXTRA_OPTS=$EXTRA_FLAGS
416 fi
417
418 # Define extra nova conf flags by defining the array ``EXTRA_OPTS``.
419 # For Example: ``EXTRA_OPTS=(foo=true bar=2)``
420 for I in "${EXTRA_OPTS[@]}"; do
421 # Attempt to convert flags to options
422 add_nova_opt ${I//--}
423 done
Dean Troyerda7b8092012-10-08 18:12:14 -0500424}
Dean Troyerbf67c192012-09-21 15:09:37 -0500425
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900426function create_nova_conf_nova_network() {
427 add_nova_opt "network_manager=nova.network.manager.$NET_MAN"
428 add_nova_opt "public_interface=$PUBLIC_INTERFACE"
429 add_nova_opt "vlan_interface=$VLAN_INTERFACE"
430 add_nova_opt "flat_network_bridge=$FLAT_NETWORK_BRIDGE"
431 if [ -n "$FLAT_INTERFACE" ]; then
432 add_nova_opt "flat_interface=$FLAT_INTERFACE"
433 fi
434}
435
Dean Troyerda7b8092012-10-08 18:12:14 -0500436# init_nova() - Initialize databases, etc.
437function init_nova() {
Dean Troyerbf67c192012-09-21 15:09:37 -0500438 # Nova Database
439 # -------------
440
441 # All nova components talk to a central database. We will need to do this step
442 # only once for an entire cluster.
443
Bob Melanderc439b5d2012-12-19 14:49:34 +0100444 if is_service_enabled $DATABASE_BACKENDS && is_service_enabled n-api; then
Dean Troyerbf67c192012-09-21 15:09:37 -0500445 # (Re)create nova database
Dean Troyerbf67c192012-09-21 15:09:37 -0500446 # Explicitly use latin1: to avoid lp#829209, nova expects the database to
447 # use latin1 by default, and then upgrades the database to utf8 (see the
448 # 082_essex.py in nova)
Terry Wilson428af5a2012-11-01 16:12:39 -0400449 recreate_database nova latin1
Dean Troyerbf67c192012-09-21 15:09:37 -0500450
451 # (Re)create nova database
452 $NOVA_BIN_DIR/nova-manage db sync
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800453
454 # (Re)create nova baremetal database
455 if is_baremetal; then
456 recreate_database nova_bm latin1
457 $NOVA_BIN_DIR/nova-baremetal-manage db sync
458 fi
Dean Troyerbf67c192012-09-21 15:09:37 -0500459 fi
460
Akihiro MOTOKI5e3deb62012-12-11 17:09:02 +0900461 # Create cache dir
462 sudo mkdir -p $NOVA_AUTH_CACHE_DIR
463 sudo chown `whoami` $NOVA_AUTH_CACHE_DIR
Vishvananda Ishaya23431f32012-12-12 15:57:33 -0800464 rm -f $NOVA_AUTH_CACHE_DIR/*
Devananda van der Veenf35cf912012-11-12 17:58:38 -0800465
466 # Create the keys folder
467 sudo mkdir -p ${NOVA_STATE_PATH}/keys
468 # make sure we own NOVA_STATE_PATH and all subdirs
469 sudo chown -R `whoami` ${NOVA_STATE_PATH}
Dean Troyerbf67c192012-09-21 15:09:37 -0500470}
471
472# install_novaclient() - Collect source and prepare
473function install_novaclient() {
474 git_clone $NOVACLIENT_REPO $NOVACLIENT_DIR $NOVACLIENT_BRANCH
475}
476
477# install_nova() - Collect source and prepare
478function install_nova() {
479 if is_service_enabled n-cpu; then
Vincent Untzc18b9652012-12-04 12:36:34 +0100480 if is_ubuntu; then
Vincent Untz00011c02012-12-06 09:56:32 +0100481 install_package libvirt-bin
482 elif is_fedora || is_suse; then
483 install_package libvirt
Dean Troyerbf67c192012-09-21 15:09:37 -0500484 else
Vincent Untz00011c02012-12-06 09:56:32 +0100485 exit_distro_not_supported "libvirt installation"
Dean Troyerbf67c192012-09-21 15:09:37 -0500486 fi
Vincent Untz00011c02012-12-06 09:56:32 +0100487
Dean Troyerbf67c192012-09-21 15:09:37 -0500488 # Install and configure **LXC** if specified. LXC is another approach to
489 # splitting a system into many smaller parts. LXC uses cgroups and chroot
490 # to simulate multiple systems.
491 if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then
Vincent Untzc18b9652012-12-04 12:36:34 +0100492 if is_ubuntu; then
Dean Troyerbf67c192012-09-21 15:09:37 -0500493 if [[ "$DISTRO" > natty ]]; then
494 install_package cgroup-lite
495 fi
496 else
497 ### FIXME(dtroyer): figure this out
498 echo "RPM-based cgroup not implemented yet"
499 yum_install libcgroup-tools
500 fi
501 fi
502 fi
503
504 git_clone $NOVA_REPO $NOVA_DIR $NOVA_BRANCH
505}
506
507# start_nova() - Start running processes, including screen
508function start_nova() {
509 # The group **libvirtd** is added to the current user in this script.
510 # Use 'sg' to execute nova-compute as a member of the **libvirtd** group.
511 # ``screen_it`` checks ``is_service_enabled``, it is not needed here
Russell Bryantff7f3082012-11-29 22:00:51 -0500512 screen_it n-cond "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-conductor"
Dean Troyerbf67c192012-09-21 15:09:37 -0500513 screen_it n-cpu "cd $NOVA_DIR && sg libvirtd $NOVA_BIN_DIR/nova-compute"
514 screen_it n-crt "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-cert"
515 screen_it n-net "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-network"
516 screen_it n-sch "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-scheduler"
Dean Troyer3cf1ffb2012-10-02 11:51:27 -0500517 screen_it n-novnc "cd $NOVNC_DIR && ./utils/nova-novncproxy --config-file $NOVA_CONF --web ."
Monty Taylor0edfd6f2012-11-23 15:00:38 -0800518 screen_it n-xvnc "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-xvpvncproxy --config-file $NOVA_CONF"
519 screen_it n-cauth "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-consoleauth"
Dean Troyerbf67c192012-09-21 15:09:37 -0500520}
521
522# stop_nova() - Stop running processes (non-screen)
523function stop_nova() {
524 # Kill the nova screen windows
Dan Smithd57ccf02012-11-15 10:09:33 -0800525 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 -0500526 screen -S $SCREEN_NAME -p $serv -X kill
527 done
528}
529
530# Restore xtrace
531$XTRACE