blob: 42d3af15cf45785bd230d22845afbe13678e04f5 [file] [log] [blame]
Dean Troyer8c032d12013-09-23 13:53:13 -05001# lib/nova_plugins/hypervisor-libvirt
2# Configure the libvirt hypervisor
3
4# Enable with:
5# VIRT_DRIVER=libvirt
6
7# Dependencies:
8# ``functions`` file
9# ``nova`` configuration
Stephan Renatuse578eff2013-11-19 13:31:04 +010010# ``STACK_USER`` has to be defined
Dean Troyer8c032d12013-09-23 13:53:13 -050011
12# install_nova_hypervisor - install any external requirements
13# configure_nova_hypervisor - make configuration changes, including those to other services
14# start_nova_hypervisor - start any external services
15# stop_nova_hypervisor - stop any external services
16# cleanup_nova_hypervisor - remove transient data and cache
17
18# Save trace setting
19MY_XTRACE=$(set +o | grep xtrace)
20set +o xtrace
21
22
23# Defaults
24# --------
25
26
27# Entry Points
28# ------------
29
30# clean_nova_hypervisor - Clean up an installation
31function cleanup_nova_hypervisor() {
32 # This function intentionally left blank
33 :
34}
35
36# configure_nova_hypervisor - Set config files, create data dirs, etc
37function configure_nova_hypervisor() {
38 if is_service_enabled neutron && is_neutron_ovs_base_plugin && ! sudo grep -q '^cgroup_device_acl' $QEMU_CONF; then
39 # Add /dev/net/tun to cgroup_device_acls, needed for type=ethernet interfaces
40 cat <<EOF | sudo tee -a $QEMU_CONF
41cgroup_device_acl = [
42 "/dev/null", "/dev/full", "/dev/zero",
43 "/dev/random", "/dev/urandom",
44 "/dev/ptmx", "/dev/kvm", "/dev/kqemu",
45 "/dev/rtc", "/dev/hpet","/dev/net/tun",
46]
47EOF
48 fi
49
50 if is_ubuntu; then
51 LIBVIRT_DAEMON=libvirt-bin
52 else
53 LIBVIRT_DAEMON=libvirtd
54 fi
55
56 if is_fedora || is_suse; then
57 if is_fedora && [[ $DISTRO =~ (rhel6) || "$os_RELEASE" -le "17" ]]; then
58 sudo bash -c "cat <<EOF >/etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
59[libvirt Management Access]
60Identity=unix-group:$LIBVIRT_GROUP
61Action=org.libvirt.unix.manage
62ResultAny=yes
63ResultInactive=yes
64ResultActive=yes
65EOF"
66 elif is_suse && [[ $os_RELEASE = 12.2 || "$os_VENDOR" = "SUSE LINUX" ]]; then
67 # openSUSE < 12.3 or SLE
68 # Work around the fact that polkit-default-privs overrules pklas
69 # with 'unix-group:$group'.
70 sudo bash -c "cat <<EOF >/etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
71[libvirt Management Access]
Stephan Renatuse578eff2013-11-19 13:31:04 +010072Identity=unix-user:$STACK_USER
Dean Troyer8c032d12013-09-23 13:53:13 -050073Action=org.libvirt.unix.manage
74ResultAny=yes
75ResultInactive=yes
76ResultActive=yes
77EOF"
78 else
79 # Starting with fedora 18 and opensuse-12.3 enable stack-user to
80 # virsh -c qemu:///system by creating a policy-kit rule for
81 # stack-user using the new Javascript syntax
82 rules_dir=/etc/polkit-1/rules.d
83 sudo mkdir -p $rules_dir
84 sudo bash -c "cat <<EOF > $rules_dir/50-libvirt-$STACK_USER.rules
85polkit.addRule(function(action, subject) {
Sean Dague101b4242013-10-22 08:47:11 -040086 if (action.id == 'org.libvirt.unix.manage' &&
87 subject.user == '"$STACK_USER"') {
88 return polkit.Result.YES;
89 }
Dean Troyer8c032d12013-09-23 13:53:13 -050090});
91EOF"
92 unset rules_dir
93 fi
94 fi
95
Dean Troyer8c032d12013-09-23 13:53:13 -050096 # The user that nova runs as needs to be member of **libvirtd** group otherwise
97 # nova-compute will be unable to use libvirt.
98 if ! getent group $LIBVIRT_GROUP >/dev/null; then
99 sudo groupadd $LIBVIRT_GROUP
100 fi
101 add_user_to_group $STACK_USER $LIBVIRT_GROUP
102
103 # libvirt detects various settings on startup, as we potentially changed
104 # the system configuration (modules, filesystems), we need to restart
105 # libvirt to detect those changes.
106 restart_service $LIBVIRT_DAEMON
107
108 iniset $NOVA_CONF DEFAULT libvirt_type "$LIBVIRT_TYPE"
109 iniset $NOVA_CONF DEFAULT libvirt_cpu_mode "none"
110 iniset $NOVA_CONF DEFAULT use_usb_tablet "False"
Sean Dague6bf1f1f2014-02-01 17:05:18 -0500111 iniset $NOVA_CONF DEFAULT default_ephemeral_format "ext4"
Dean Troyer8c032d12013-09-23 13:53:13 -0500112 iniset $NOVA_CONF DEFAULT compute_driver "libvirt.LibvirtDriver"
113 LIBVIRT_FIREWALL_DRIVER=${LIBVIRT_FIREWALL_DRIVER:-"nova.virt.libvirt.firewall.IptablesFirewallDriver"}
114 iniset $NOVA_CONF DEFAULT firewall_driver "$LIBVIRT_FIREWALL_DRIVER"
115 # Power architecture currently does not support graphical consoles.
116 if is_arch "ppc64"; then
117 iniset $NOVA_CONF DEFAULT vnc_enabled "false"
118 fi
119}
120
121# install_nova_hypervisor() - Install external components
122function install_nova_hypervisor() {
123 if is_ubuntu; then
124 install_package kvm
125 install_package libvirt-bin
126 install_package python-libvirt
127 elif is_fedora || is_suse; then
128 install_package kvm
129 install_package libvirt
130 install_package libvirt-python
131 fi
132
133 # Install and configure **LXC** if specified. LXC is another approach to
134 # splitting a system into many smaller parts. LXC uses cgroups and chroot
135 # to simulate multiple systems.
136 if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then
137 if is_ubuntu; then
138 if [[ "$DISTRO" > natty ]]; then
139 install_package cgroup-lite
140 fi
141 else
142 ### FIXME(dtroyer): figure this out
143 echo "RPM-based cgroup not implemented yet"
144 yum_install libcgroup-tools
145 fi
146 fi
147}
148
149# start_nova_hypervisor - Start any required external services
150function start_nova_hypervisor() {
151 # This function intentionally left blank
152 :
153}
154
155# stop_nova_hypervisor - Stop any external services
156function stop_nova_hypervisor() {
157 # This function intentionally left blank
158 :
159}
160
161
162# Restore xtrace
163$MY_XTRACE
164
165# Local variables:
166# mode: shell-script
167# End: