blob: ef40e7ab4c074e497df555f8d40aef088f41ff9d [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
Ken'ichi Ohmichi3bd85c92013-12-25 22:14:11 +090096 # Change the libvirtd log level to DEBUG.
97 sudo sed -i s/"#log_level = 3"/"log_level = 1"/ /etc/libvirt/libvirtd.conf
98
Dean Troyer8c032d12013-09-23 13:53:13 -050099 # The user that nova runs as needs to be member of **libvirtd** group otherwise
100 # nova-compute will be unable to use libvirt.
101 if ! getent group $LIBVIRT_GROUP >/dev/null; then
102 sudo groupadd $LIBVIRT_GROUP
103 fi
104 add_user_to_group $STACK_USER $LIBVIRT_GROUP
105
106 # libvirt detects various settings on startup, as we potentially changed
107 # the system configuration (modules, filesystems), we need to restart
108 # libvirt to detect those changes.
109 restart_service $LIBVIRT_DAEMON
110
111 iniset $NOVA_CONF DEFAULT libvirt_type "$LIBVIRT_TYPE"
112 iniset $NOVA_CONF DEFAULT libvirt_cpu_mode "none"
113 iniset $NOVA_CONF DEFAULT use_usb_tablet "False"
114 iniset $NOVA_CONF DEFAULT compute_driver "libvirt.LibvirtDriver"
115 LIBVIRT_FIREWALL_DRIVER=${LIBVIRT_FIREWALL_DRIVER:-"nova.virt.libvirt.firewall.IptablesFirewallDriver"}
116 iniset $NOVA_CONF DEFAULT firewall_driver "$LIBVIRT_FIREWALL_DRIVER"
117 # Power architecture currently does not support graphical consoles.
118 if is_arch "ppc64"; then
119 iniset $NOVA_CONF DEFAULT vnc_enabled "false"
120 fi
121}
122
123# install_nova_hypervisor() - Install external components
124function install_nova_hypervisor() {
125 if is_ubuntu; then
126 install_package kvm
127 install_package libvirt-bin
128 install_package python-libvirt
129 elif is_fedora || is_suse; then
130 install_package kvm
131 install_package libvirt
132 install_package libvirt-python
133 fi
134
135 # Install and configure **LXC** if specified. LXC is another approach to
136 # splitting a system into many smaller parts. LXC uses cgroups and chroot
137 # to simulate multiple systems.
138 if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then
139 if is_ubuntu; then
140 if [[ "$DISTRO" > natty ]]; then
141 install_package cgroup-lite
142 fi
143 else
144 ### FIXME(dtroyer): figure this out
145 echo "RPM-based cgroup not implemented yet"
146 yum_install libcgroup-tools
147 fi
148 fi
149}
150
151# start_nova_hypervisor - Start any required external services
152function start_nova_hypervisor() {
153 # This function intentionally left blank
154 :
155}
156
157# stop_nova_hypervisor - Stop any external services
158function stop_nova_hypervisor() {
159 # This function intentionally left blank
160 :
161}
162
163
164# Restore xtrace
165$MY_XTRACE
166
167# Local variables:
168# mode: shell-script
169# End: