blob: 9530df4618dee1d1b9b6d80813324bb333b4f034 [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
Dean Troyerbc071bc2012-10-01 14:06:44 -0500175 if [[ "$KEYSTONE_TOKEN_FORMAT" == "PKI" ]]; then
176 iniset $NOVA_API_PASTE_INI filter:authtoken signing_dir $NOVA_AUTH_CACHE_DIR
177 fi
178
Dean Troyerbf67c192012-09-21 15:09:37 -0500179 if is_service_enabled n-cpu; then
180 # Force IP forwarding on, just on case
181 sudo sysctl -w net.ipv4.ip_forward=1
182
183 # Attempt to load modules: network block device - used to manage qcow images
184 sudo modprobe nbd || true
185
186 # Check for kvm (hardware based virtualization). If unable to initialize
187 # kvm, we drop back to the slower emulation mode (qemu). Note: many systems
188 # come with hardware virtualization disabled in BIOS.
189 if [[ "$LIBVIRT_TYPE" == "kvm" ]]; then
190 sudo modprobe kvm || true
191 if [ ! -e /dev/kvm ]; then
192 echo "WARNING: Switching to QEMU"
193 LIBVIRT_TYPE=qemu
194 if which selinuxenabled 2>&1 > /dev/null && selinuxenabled; then
195 # https://bugzilla.redhat.com/show_bug.cgi?id=753589
196 sudo setsebool virt_use_execmem on
197 fi
198 fi
199 fi
200
201 # Install and configure **LXC** if specified. LXC is another approach to
202 # splitting a system into many smaller parts. LXC uses cgroups and chroot
203 # to simulate multiple systems.
204 if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then
Vincent Untzc18b9652012-12-04 12:36:34 +0100205 if is_ubuntu; then
Dean Troyerbf67c192012-09-21 15:09:37 -0500206 if [[ ! "$DISTRO" > natty ]]; then
207 cgline="none /cgroup cgroup cpuacct,memory,devices,cpu,freezer,blkio 0 0"
208 sudo mkdir -p /cgroup
209 if ! grep -q cgroup /etc/fstab; then
210 echo "$cgline" | sudo tee -a /etc/fstab
211 fi
212 if ! mount -n | grep -q cgroup; then
213 sudo mount /cgroup
214 fi
215 fi
216 fi
217 fi
218
Yoshihiro Kaneko602cf9b2012-07-23 06:27:36 +0000219 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 -0500220 # Add /dev/net/tun to cgroup_device_acls, needed for type=ethernet interfaces
221 cat <<EOF | sudo tee -a $QEMU_CONF
222cgroup_device_acl = [
223 "/dev/null", "/dev/full", "/dev/zero",
224 "/dev/random", "/dev/urandom",
225 "/dev/ptmx", "/dev/kvm", "/dev/kqemu",
226 "/dev/rtc", "/dev/hpet","/dev/net/tun",
227]
228EOF
229 fi
230
Vincent Untzc18b9652012-12-04 12:36:34 +0100231 if is_ubuntu; then
Dean Troyerbf67c192012-09-21 15:09:37 -0500232 LIBVIRT_DAEMON=libvirt-bin
233 else
Vincent Untzf1c094c2012-12-05 17:59:04 +0100234 LIBVIRT_DAEMON=libvirtd
235 fi
236
237 # For distributions using polkit to authorize access to libvirt,
238 # configure polkit accordingly.
239 # Based on http://wiki.libvirt.org/page/SSHPolicyKitSetup
240 if is_fedora; then
Dean Troyerbf67c192012-09-21 15:09:37 -0500241 sudo bash -c 'cat <<EOF >/etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
242[libvirt Management Access]
243Identity=unix-group:libvirtd
244Action=org.libvirt.unix.manage
245ResultAny=yes
246ResultInactive=yes
247ResultActive=yes
248EOF'
Vincent Untzf1c094c2012-12-05 17:59:04 +0100249 elif is_suse; then
250 # Work around the fact that polkit-default-privs overrules pklas
251 # with 'unix-group:$group'.
252 sudo bash -c "cat <<EOF >/etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
253[libvirt Management Access]
254Identity=unix-user:$USER
255Action=org.libvirt.unix.manage
256ResultAny=yes
257ResultInactive=yes
258ResultActive=yes
259EOF"
Dean Troyerbf67c192012-09-21 15:09:37 -0500260 fi
261
262 # The user that nova runs as needs to be member of **libvirtd** group otherwise
263 # nova-compute will be unable to use libvirt.
Vincent Untzf1c094c2012-12-05 17:59:04 +0100264 if ! getent group libvirtd >/dev/null; then
265 sudo groupadd libvirtd
266 fi
Vincent Untz856a11e2012-11-21 16:04:12 +0100267 add_user_to_group `whoami` libvirtd
Dean Troyerbf67c192012-09-21 15:09:37 -0500268
269 # libvirt detects various settings on startup, as we potentially changed
270 # the system configuration (modules, filesystems), we need to restart
271 # libvirt to detect those changes.
272 restart_service $LIBVIRT_DAEMON
273
274
275 # Instance Storage
276 # ----------------
277
278 # Nova stores each instance in its own directory.
279 mkdir -p $NOVA_INSTANCES_PATH
280
281 # You can specify a different disk to be mounted and used for backing the
282 # virtual machines. If there is a partition labeled nova-instances we
283 # mount it (ext filesystems can be labeled via e2label).
284 if [ -L /dev/disk/by-label/nova-instances ]; then
285 if ! mount -n | grep -q $NOVA_INSTANCES_PATH; then
286 sudo mount -L nova-instances $NOVA_INSTANCES_PATH
287 sudo chown -R `whoami` $NOVA_INSTANCES_PATH
288 fi
289 fi
290
291 # Clean up old instances
292 cleanup_nova
293 fi
294}
295
Dean Troyera0dce262012-12-11 16:52:37 -0600296# create_nova_accounts() - Set up common required nova accounts
297
298# Tenant User Roles
299# ------------------------------------------------------------------
300# service nova admin, [ResellerAdmin (swift only)]
301
302# Migrated from keystone_data.sh
303create_nova_accounts() {
304
305 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
306 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
307
308 # Nova
309 if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
310 NOVA_USER=$(keystone user-create \
311 --name=nova \
312 --pass="$SERVICE_PASSWORD" \
313 --tenant_id $SERVICE_TENANT \
314 --email=nova@example.com \
315 | grep " id " | get_field 2)
316 keystone user-role-add \
317 --tenant_id $SERVICE_TENANT \
318 --user_id $NOVA_USER \
319 --role_id $ADMIN_ROLE
320 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
321 NOVA_SERVICE=$(keystone service-create \
322 --name=nova \
323 --type=compute \
324 --description="Nova Compute Service" \
325 | grep " id " | get_field 2)
326 keystone endpoint-create \
327 --region RegionOne \
328 --service_id $NOVA_SERVICE \
329 --publicurl "http://$SERVICE_HOST:\$(compute_port)s/v2/\$(tenant_id)s" \
330 --adminurl "http://$SERVICE_HOST:\$(compute_port)s/v2/\$(tenant_id)s" \
331 --internalurl "http://$SERVICE_HOST:\$(compute_port)s/v2/\$(tenant_id)s"
332 fi
333 fi
334}
335
Dean Troyerda7b8092012-10-08 18:12:14 -0500336# create_nova_conf() - Create a new nova.conf file
337function create_nova_conf() {
Dean Troyerbf67c192012-09-21 15:09:37 -0500338 # Remove legacy ``nova.conf``
339 rm -f $NOVA_DIR/bin/nova.conf
340
341 # (Re)create ``nova.conf``
Dean Troyer3cf1ffb2012-10-02 11:51:27 -0500342 rm -f $NOVA_CONF
Dean Troyerbf67c192012-09-21 15:09:37 -0500343 add_nova_opt "[DEFAULT]"
344 add_nova_opt "verbose=True"
345 add_nova_opt "auth_strategy=keystone"
346 add_nova_opt "allow_resize_to_same_host=True"
347 add_nova_opt "api_paste_config=$NOVA_API_PASTE_INI"
348 add_nova_opt "rootwrap_config=$NOVA_CONF_DIR/rootwrap.conf"
349 add_nova_opt "compute_scheduler_driver=$SCHEDULER"
Dean Troyer3cf1ffb2012-10-02 11:51:27 -0500350 add_nova_opt "dhcpbridge_flagfile=$NOVA_CONF"
Dean Troyerbf67c192012-09-21 15:09:37 -0500351 add_nova_opt "force_dhcp_release=True"
352 add_nova_opt "fixed_range=$FIXED_RANGE"
353 add_nova_opt "s3_host=$SERVICE_HOST"
354 add_nova_opt "s3_port=$S3_SERVICE_PORT"
355 add_nova_opt "osapi_compute_extension=nova.api.openstack.compute.contrib.standard_extensions"
356 add_nova_opt "my_ip=$HOST_IP"
Terry Wilson428af5a2012-11-01 16:12:39 -0400357 local dburl
358 database_connection_url dburl nova
359 add_nova_opt "sql_connection=$dburl"
Dean Troyerbf67c192012-09-21 15:09:37 -0500360 add_nova_opt "libvirt_type=$LIBVIRT_TYPE"
361 add_nova_opt "libvirt_cpu_mode=none"
362 add_nova_opt "instance_name_template=${INSTANCE_NAME_PREFIX}%08x"
Dean Troyerbf67c192012-09-21 15:09:37 -0500363
364 if is_service_enabled n-api; then
365 add_nova_opt "enabled_apis=$NOVA_ENABLED_APIS"
366 fi
Dean Troyerbf67c192012-09-21 15:09:37 -0500367 if is_service_enabled cinder; then
368 add_nova_opt "volume_api_class=nova.volume.cinder.API"
369 fi
370 if [ -n "$NOVA_STATE_PATH" ]; then
371 add_nova_opt "state_path=$NOVA_STATE_PATH"
Dean Troyer13314452012-10-23 15:09:50 -0500372 add_nova_opt "lock_path=$NOVA_STATE_PATH"
Dean Troyerbf67c192012-09-21 15:09:37 -0500373 fi
374 if [ -n "$NOVA_INSTANCES_PATH" ]; then
375 add_nova_opt "instances_path=$NOVA_INSTANCES_PATH"
376 fi
377 if [ "$MULTI_HOST" != "False" ]; then
378 add_nova_opt "multi_host=True"
379 add_nova_opt "send_arp_for_ha=True"
380 fi
381 if [ "$SYSLOG" != "False" ]; then
382 add_nova_opt "use_syslog=True"
383 fi
384 if [ "$API_RATE_LIMIT" != "True" ]; then
385 add_nova_opt "api_rate_limit=False"
386 fi
387 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
388 # Add color to logging output
389 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"
390 add_nova_opt "logging_default_format_string=%(asctime)s %(color)s%(levelname)s %(name)s [-%(color)s] %(instance)s%(color)s%(message)s"
391 add_nova_opt "logging_debug_format_suffix=from (pid=%(process)d) %(funcName)s %(pathname)s:%(lineno)d"
392 add_nova_opt "logging_exception_prefix=%(color)s%(asctime)s TRACE %(name)s %(instance)s"
393 else
394 # Show user_name and project_name instead of user_id and project_id
395 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"
396 fi
Eoghan Glynn1fcc6a12012-10-25 14:57:14 +0000397 if is_service_enabled ceilometer; then
398 add_nova_opt "instance_usage_audit=True"
399 add_nova_opt "instance_usage_audit_period=hour"
400 add_nova_opt "notification_driver=nova.openstack.common.notifier.rabbit_notifier"
401 add_nova_opt "notification_driver=ceilometer.compute.nova_notifier"
402 fi
403
Dean Troyerbf67c192012-09-21 15:09:37 -0500404
405 # Provide some transition from ``EXTRA_FLAGS`` to ``EXTRA_OPTS``
406 if [[ -z "$EXTRA_OPTS" && -n "$EXTRA_FLAGS" ]]; then
407 EXTRA_OPTS=$EXTRA_FLAGS
408 fi
409
410 # Define extra nova conf flags by defining the array ``EXTRA_OPTS``.
411 # For Example: ``EXTRA_OPTS=(foo=true bar=2)``
412 for I in "${EXTRA_OPTS[@]}"; do
413 # Attempt to convert flags to options
414 add_nova_opt ${I//--}
415 done
Dean Troyerda7b8092012-10-08 18:12:14 -0500416}
Dean Troyerbf67c192012-09-21 15:09:37 -0500417
Dean Troyerda7b8092012-10-08 18:12:14 -0500418# init_nova() - Initialize databases, etc.
419function init_nova() {
Dean Troyerbf67c192012-09-21 15:09:37 -0500420 # Nova Database
421 # -------------
422
423 # All nova components talk to a central database. We will need to do this step
424 # only once for an entire cluster.
425
Terry Wilson428af5a2012-11-01 16:12:39 -0400426 if is_service_enabled $DATABASE_BACKENDS && is_service_enabled nova; then
Dean Troyerbf67c192012-09-21 15:09:37 -0500427 # (Re)create nova database
Dean Troyerbf67c192012-09-21 15:09:37 -0500428 # Explicitly use latin1: to avoid lp#829209, nova expects the database to
429 # use latin1 by default, and then upgrades the database to utf8 (see the
430 # 082_essex.py in nova)
Terry Wilson428af5a2012-11-01 16:12:39 -0400431 recreate_database nova latin1
Dean Troyerbf67c192012-09-21 15:09:37 -0500432
433 # (Re)create nova database
434 $NOVA_BIN_DIR/nova-manage db sync
435 fi
436
Dean Troyerbc071bc2012-10-01 14:06:44 -0500437 if [[ "$KEYSTONE_TOKEN_FORMAT" == "PKI" ]]; then
438 # Create cache dir
439 sudo mkdir -p $NOVA_AUTH_CACHE_DIR
440 sudo chown `whoami` $NOVA_AUTH_CACHE_DIR
441 fi
Dean Troyerbf67c192012-09-21 15:09:37 -0500442}
443
444# install_novaclient() - Collect source and prepare
445function install_novaclient() {
446 git_clone $NOVACLIENT_REPO $NOVACLIENT_DIR $NOVACLIENT_BRANCH
447}
448
449# install_nova() - Collect source and prepare
450function install_nova() {
451 if is_service_enabled n-cpu; then
Vincent Untzc18b9652012-12-04 12:36:34 +0100452 if is_ubuntu; then
Vincent Untz00011c02012-12-06 09:56:32 +0100453 install_package libvirt-bin
454 elif is_fedora || is_suse; then
455 install_package libvirt
Dean Troyerbf67c192012-09-21 15:09:37 -0500456 else
Vincent Untz00011c02012-12-06 09:56:32 +0100457 exit_distro_not_supported "libvirt installation"
Dean Troyerbf67c192012-09-21 15:09:37 -0500458 fi
Vincent Untz00011c02012-12-06 09:56:32 +0100459
Dean Troyerbf67c192012-09-21 15:09:37 -0500460 # Install and configure **LXC** if specified. LXC is another approach to
461 # splitting a system into many smaller parts. LXC uses cgroups and chroot
462 # to simulate multiple systems.
463 if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then
Vincent Untzc18b9652012-12-04 12:36:34 +0100464 if is_ubuntu; then
Dean Troyerbf67c192012-09-21 15:09:37 -0500465 if [[ "$DISTRO" > natty ]]; then
466 install_package cgroup-lite
467 fi
468 else
469 ### FIXME(dtroyer): figure this out
470 echo "RPM-based cgroup not implemented yet"
471 yum_install libcgroup-tools
472 fi
473 fi
474 fi
475
476 git_clone $NOVA_REPO $NOVA_DIR $NOVA_BRANCH
477}
478
479# start_nova() - Start running processes, including screen
480function start_nova() {
481 # The group **libvirtd** is added to the current user in this script.
482 # Use 'sg' to execute nova-compute as a member of the **libvirtd** group.
483 # ``screen_it`` checks ``is_service_enabled``, it is not needed here
Russell Bryantff7f3082012-11-29 22:00:51 -0500484 screen_it n-cond "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-conductor"
Dean Troyerbf67c192012-09-21 15:09:37 -0500485 screen_it n-cpu "cd $NOVA_DIR && sg libvirtd $NOVA_BIN_DIR/nova-compute"
486 screen_it n-crt "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-cert"
487 screen_it n-net "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-network"
488 screen_it n-sch "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-scheduler"
Dean Troyer3cf1ffb2012-10-02 11:51:27 -0500489 screen_it n-novnc "cd $NOVNC_DIR && ./utils/nova-novncproxy --config-file $NOVA_CONF --web ."
Monty Taylor0edfd6f2012-11-23 15:00:38 -0800490 screen_it n-xvnc "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-xvpvncproxy --config-file $NOVA_CONF"
491 screen_it n-cauth "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-consoleauth"
Dean Troyerbf67c192012-09-21 15:09:37 -0500492}
493
494# stop_nova() - Stop running processes (non-screen)
495function stop_nova() {
496 # Kill the nova screen windows
Dan Smithd57ccf02012-11-15 10:09:33 -0800497 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 -0500498 screen -S $SCREEN_NAME -p $serv -X kill
499 done
500}
501
502# Restore xtrace
503$XTRACE