blob: 87c3d3addcadbb5b7ae02ab097c196b3eb25aae2 [file] [log] [blame]
Sean Daguee263c822014-12-05 14:25:28 -05001#!/bin/bash
2#
Dean Troyer8c032d12013-09-23 13:53:13 -05003# lib/nova_plugins/hypervisor-libvirt
4# Configure the libvirt hypervisor
5
6# Enable with:
7# VIRT_DRIVER=libvirt
8
9# Dependencies:
10# ``functions`` file
11# ``nova`` configuration
12
13# install_nova_hypervisor - install any external requirements
14# configure_nova_hypervisor - make configuration changes, including those to other services
15# start_nova_hypervisor - start any external services
16# stop_nova_hypervisor - stop any external services
17# cleanup_nova_hypervisor - remove transient data and cache
18
19# Save trace setting
Ian Wienand523f4882015-10-13 11:03:03 +110020_XTRACE_NOVA_LIBVIRT=$(set +o | grep xtrace)
Dean Troyer8c032d12013-09-23 13:53:13 -050021set +o xtrace
22
Adam Gandelman0f73ff22014-03-13 14:20:43 -070023source $TOP_DIR/lib/nova_plugins/functions-libvirt
Dean Troyer8c032d12013-09-23 13:53:13 -050024
25# Defaults
26# --------
27
28
29# Entry Points
30# ------------
31
32# clean_nova_hypervisor - Clean up an installation
Ian Wienandaee18c72014-02-21 15:35:08 +110033function cleanup_nova_hypervisor {
Dean Troyer8c032d12013-09-23 13:53:13 -050034 # This function intentionally left blank
35 :
36}
37
38# configure_nova_hypervisor - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +110039function configure_nova_hypervisor {
Adam Gandelman0f73ff22014-03-13 14:20:43 -070040 configure_libvirt
Joe Gordon1cd8efc2014-04-17 16:46:36 -070041 iniset $NOVA_CONF libvirt virt_type "$LIBVIRT_TYPE"
Carlos Goncalves8dd6f152020-01-20 07:24:17 +010042 iniset $NOVA_CONF libvirt cpu_mode "$LIBVIRT_CPU_MODE"
Clark Boylane06d9542021-10-21 08:15:12 -070043 if [ "$LIBVIRT_CPU_MODE" == "custom" ] ; then
44 iniset $NOVA_CONF libvirt cpu_model "$LIBVIRT_CPU_MODEL"
45 fi
Matt Riedemann14cb4902016-09-08 13:07:59 -040046 # Do not enable USB tablet input devices to avoid QEMU CPU overhead.
47 iniset $NOVA_CONF DEFAULT pointer_model "ps2mouse"
Adam Gandelmana1ffcfa2014-11-20 16:42:32 -080048 iniset $NOVA_CONF libvirt live_migration_uri "qemu+ssh://$STACK_USER@%s/system"
Sean Dague6bf1f1f2014-02-01 17:05:18 -050049 iniset $NOVA_CONF DEFAULT default_ephemeral_format "ext4"
Dean Troyer8c032d12013-09-23 13:53:13 -050050 iniset $NOVA_CONF DEFAULT compute_driver "libvirt.LibvirtDriver"
Dean Troyer8c032d12013-09-23 13:53:13 -050051 # Power architecture currently does not support graphical consoles.
52 if is_arch "ppc64"; then
Mahito OGURAcf4f7622015-08-12 10:21:27 +090053 iniset $NOVA_CONF vnc enabled "false"
Dean Troyer8c032d12013-09-23 13:53:13 -050054 fi
Russell Bryant5705db62014-02-01 20:06:42 -050055
Clark Laughlinfcc3f6e2015-04-07 16:31:47 +000056 # arm64-specific configuration
57 if is_arch "aarch64"; then
Kevin Zhao5d7992a2016-07-19 15:52:12 +000058 iniset $NOVA_CONF libvirt cpu_mode "host-passthrough"
Clark Laughlinfcc3f6e2015-04-07 16:31:47 +000059 fi
60
Matt Riedemann6d3670a2016-07-03 19:40:25 -040061 if isset ENABLE_FILE_INJECTION; then
62 if [ "$ENABLE_FILE_INJECTION" == "True" ]; then
63 # -1 means use libguestfs to inspect the guest OS image for the
64 # root partition to use for file injection.
65 iniset $NOVA_CONF libvirt inject_partition '-1'
66 fi
67 fi
68
Evgeny Antyshev19354582014-11-24 14:20:35 +040069 if [[ "$LIBVIRT_TYPE" = "parallels" ]]; then
70 iniset $NOVA_CONF libvirt connection_uri "parallels+unix:///system"
71 iniset $NOVA_CONF libvirt images_type "ploop"
Maxim Nestratove6f37b92015-06-30 14:54:12 +030072 iniset $NOVA_CONF DEFAULT force_raw_images "False"
jianghua wang843b0392017-09-21 14:16:06 +000073 iniset $NOVA_CONF vnc server_proxyclient_address $HOST_IP
74 iniset $NOVA_CONF vnc server_listen $HOST_IP
Mahito OGURAcf4f7622015-08-12 10:21:27 +090075 iniset $NOVA_CONF vnc keymap
Matt Riedemann9278eb72016-05-18 13:38:38 -040076 elif [[ "$NOVA_BACKEND" == "LVM" ]]; then
77 iniset $NOVA_CONF libvirt images_type "lvm"
78 iniset $NOVA_CONF libvirt images_volume_group $DEFAULT_VOLUME_GROUP_NAME
79 if isset LVM_VOLUME_CLEAR; then
80 iniset $NOVA_CONF libvirt volume_clear "$LVM_VOLUME_CLEAR"
81 fi
Evgeny Antyshev19354582014-11-24 14:20:35 +040082 fi
Dean Troyer8c032d12013-09-23 13:53:13 -050083}
84
85# install_nova_hypervisor() - Install external components
Ian Wienandaee18c72014-02-21 15:35:08 +110086function install_nova_hypervisor {
Adam Gandelman0f73ff22014-03-13 14:20:43 -070087 install_libvirt
Dean Troyer8c032d12013-09-23 13:53:13 -050088
89 # Install and configure **LXC** if specified. LXC is another approach to
90 # splitting a system into many smaller parts. LXC uses cgroups and chroot
91 # to simulate multiple systems.
92 if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then
93 if is_ubuntu; then
94 if [[ "$DISTRO" > natty ]]; then
95 install_package cgroup-lite
96 fi
97 else
98 ### FIXME(dtroyer): figure this out
99 echo "RPM-based cgroup not implemented yet"
100 yum_install libcgroup-tools
101 fi
102 fi
Matt Riedemann6390d5e2016-09-12 11:23:19 -0400103
104 if [[ "$ENABLE_FILE_INJECTION" == "True" ]] ; then
105 if is_ubuntu; then
Masayuki Igawa89acae92020-12-16 09:12:40 +0900106 install_package python3-guestfs
Andrea Frittoli1c442ee2016-11-30 20:44:44 +0000107 # NOTE(andreaf) Ubuntu kernel can only be read by root, which breaks libguestfs:
108 # https://bugs.launchpad.net/ubuntu/+source/linux/+bug/759725)
109 INSTALLED_KERNELS="$(ls /boot/vmlinuz-*)"
110 for kernel in $INSTALLED_KERNELS; do
111 STAT_OVERRIDE="root root 644 ${kernel}"
112 # unstack won't remove the statoverride, so make this idempotent
113 if [[ ! $(dpkg-statoverride --list | grep "$STAT_OVERRIDE") ]]; then
114 sudo dpkg-statoverride --add --update $STAT_OVERRIDE
115 fi
116 done
Dirk Muellera6467d32017-06-27 08:31:26 +0200117 elif is_fedora; then
Ian Wienand9b8b7022020-04-16 13:03:56 +1000118 install_package python3-libguestfs
Matt Riedemann6390d5e2016-09-12 11:23:19 -0400119 fi
120 fi
Dean Troyer8c032d12013-09-23 13:53:13 -0500121}
122
123# start_nova_hypervisor - Start any required external services
Ian Wienandaee18c72014-02-21 15:35:08 +1100124function start_nova_hypervisor {
Dean Troyer8c032d12013-09-23 13:53:13 -0500125 # This function intentionally left blank
126 :
127}
128
129# stop_nova_hypervisor - Stop any external services
Ian Wienandaee18c72014-02-21 15:35:08 +1100130function stop_nova_hypervisor {
Dean Troyer8c032d12013-09-23 13:53:13 -0500131 # This function intentionally left blank
132 :
133}
134
135
136# Restore xtrace
Ian Wienand523f4882015-10-13 11:03:03 +1100137$_XTRACE_NOVA_LIBVIRT
Dean Troyer8c032d12013-09-23 13:53:13 -0500138
139# Local variables:
140# mode: shell-script
141# End: