| Sean Dague | e263c82 | 2014-12-05 14:25:28 -0500 | [diff] [blame] | 1 | #!/bin/bash | 
|  | 2 | # | 
| Dean Troyer | 8c032d1 | 2013-09-23 13:53:13 -0500 | [diff] [blame] | 3 | # 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 Wienand | 523f488 | 2015-10-13 11:03:03 +1100 | [diff] [blame] | 20 | _XTRACE_NOVA_LIBVIRT=$(set +o | grep xtrace) | 
| Dean Troyer | 8c032d1 | 2013-09-23 13:53:13 -0500 | [diff] [blame] | 21 | set +o xtrace | 
|  | 22 |  | 
| Adam Gandelman | 0f73ff2 | 2014-03-13 14:20:43 -0700 | [diff] [blame] | 23 | source $TOP_DIR/lib/nova_plugins/functions-libvirt | 
| Dean Troyer | 8c032d1 | 2013-09-23 13:53:13 -0500 | [diff] [blame] | 24 |  | 
|  | 25 | # Defaults | 
|  | 26 | # -------- | 
|  | 27 |  | 
|  | 28 |  | 
|  | 29 | # Entry Points | 
|  | 30 | # ------------ | 
|  | 31 |  | 
|  | 32 | # clean_nova_hypervisor - Clean up an installation | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 33 | function cleanup_nova_hypervisor { | 
| Dean Troyer | 8c032d1 | 2013-09-23 13:53:13 -0500 | [diff] [blame] | 34 | # This function intentionally left blank | 
|  | 35 | : | 
|  | 36 | } | 
|  | 37 |  | 
|  | 38 | # configure_nova_hypervisor - Set config files, create data dirs, etc | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 39 | function configure_nova_hypervisor { | 
| Adam Gandelman | 0f73ff2 | 2014-03-13 14:20:43 -0700 | [diff] [blame] | 40 | configure_libvirt | 
| Joe Gordon | 1cd8efc | 2014-04-17 16:46:36 -0700 | [diff] [blame] | 41 | iniset $NOVA_CONF libvirt virt_type "$LIBVIRT_TYPE" | 
| Carlos Goncalves | 8dd6f15 | 2020-01-20 07:24:17 +0100 | [diff] [blame] | 42 | iniset $NOVA_CONF libvirt cpu_mode "$LIBVIRT_CPU_MODE" | 
| Clark Boylan | e06d954 | 2021-10-21 08:15:12 -0700 | [diff] [blame] | 43 | if [ "$LIBVIRT_CPU_MODE" == "custom" ] ; then | 
|  | 44 | iniset $NOVA_CONF libvirt cpu_model "$LIBVIRT_CPU_MODEL" | 
|  | 45 | fi | 
| Matt Riedemann | 14cb490 | 2016-09-08 13:07:59 -0400 | [diff] [blame] | 46 | # Do not enable USB tablet input devices to avoid QEMU CPU overhead. | 
|  | 47 | iniset $NOVA_CONF DEFAULT pointer_model "ps2mouse" | 
| Adam Gandelman | a1ffcfa | 2014-11-20 16:42:32 -0800 | [diff] [blame] | 48 | iniset $NOVA_CONF libvirt live_migration_uri "qemu+ssh://$STACK_USER@%s/system" | 
| Sean Dague | 6bf1f1f | 2014-02-01 17:05:18 -0500 | [diff] [blame] | 49 | iniset $NOVA_CONF DEFAULT default_ephemeral_format "ext4" | 
| Dean Troyer | 8c032d1 | 2013-09-23 13:53:13 -0500 | [diff] [blame] | 50 | iniset $NOVA_CONF DEFAULT compute_driver "libvirt.LibvirtDriver" | 
| Dean Troyer | 8c032d1 | 2013-09-23 13:53:13 -0500 | [diff] [blame] | 51 | # Power architecture currently does not support graphical consoles. | 
|  | 52 | if is_arch "ppc64"; then | 
| Mahito OGURA | cf4f762 | 2015-08-12 10:21:27 +0900 | [diff] [blame] | 53 | iniset $NOVA_CONF vnc enabled "false" | 
| Dean Troyer | 8c032d1 | 2013-09-23 13:53:13 -0500 | [diff] [blame] | 54 | fi | 
| Russell Bryant | 5705db6 | 2014-02-01 20:06:42 -0500 | [diff] [blame] | 55 |  | 
| Clark Laughlin | fcc3f6e | 2015-04-07 16:31:47 +0000 | [diff] [blame] | 56 | # arm64-specific configuration | 
|  | 57 | if is_arch "aarch64"; then | 
| Kevin Zhao | 5d7992a | 2016-07-19 15:52:12 +0000 | [diff] [blame] | 58 | iniset $NOVA_CONF libvirt cpu_mode "host-passthrough" | 
| Mohammed Naser | 28bed12 | 2022-04-20 15:11:39 -0400 | [diff] [blame^] | 59 | # NOTE(mnaser): We cannot have `cpu_model` set if the `cpu_mode` is | 
|  | 60 | #               set to `host-passthrough`, or `nova-compute` refuses to | 
|  | 61 | #               start. | 
|  | 62 | inidelete $NOVA_CONF libvirt cpu_model | 
| Clark Laughlin | fcc3f6e | 2015-04-07 16:31:47 +0000 | [diff] [blame] | 63 | fi | 
|  | 64 |  | 
| Matt Riedemann | 6d3670a | 2016-07-03 19:40:25 -0400 | [diff] [blame] | 65 | if isset ENABLE_FILE_INJECTION; then | 
|  | 66 | if [ "$ENABLE_FILE_INJECTION" == "True" ]; then | 
|  | 67 | # -1 means use libguestfs to inspect the guest OS image for the | 
|  | 68 | # root partition to use for file injection. | 
|  | 69 | iniset $NOVA_CONF libvirt inject_partition '-1' | 
|  | 70 | fi | 
|  | 71 | fi | 
|  | 72 |  | 
| Evgeny Antyshev | 1935458 | 2014-11-24 14:20:35 +0400 | [diff] [blame] | 73 | if [[ "$LIBVIRT_TYPE" = "parallels" ]]; then | 
|  | 74 | iniset $NOVA_CONF libvirt connection_uri "parallels+unix:///system" | 
|  | 75 | iniset $NOVA_CONF libvirt images_type "ploop" | 
| Maxim Nestratov | e6f37b9 | 2015-06-30 14:54:12 +0300 | [diff] [blame] | 76 | iniset $NOVA_CONF DEFAULT force_raw_images  "False" | 
| jianghua wang | 843b039 | 2017-09-21 14:16:06 +0000 | [diff] [blame] | 77 | iniset $NOVA_CONF vnc server_proxyclient_address  $HOST_IP | 
|  | 78 | iniset $NOVA_CONF vnc server_listen $HOST_IP | 
| Mahito OGURA | cf4f762 | 2015-08-12 10:21:27 +0900 | [diff] [blame] | 79 | iniset $NOVA_CONF vnc keymap | 
| Matt Riedemann | 9278eb7 | 2016-05-18 13:38:38 -0400 | [diff] [blame] | 80 | elif [[ "$NOVA_BACKEND" == "LVM" ]]; then | 
|  | 81 | iniset $NOVA_CONF libvirt images_type "lvm" | 
|  | 82 | iniset $NOVA_CONF libvirt images_volume_group $DEFAULT_VOLUME_GROUP_NAME | 
|  | 83 | if isset LVM_VOLUME_CLEAR; then | 
|  | 84 | iniset $NOVA_CONF libvirt volume_clear "$LVM_VOLUME_CLEAR" | 
|  | 85 | fi | 
| Evgeny Antyshev | 1935458 | 2014-11-24 14:20:35 +0400 | [diff] [blame] | 86 | fi | 
| Dean Troyer | 8c032d1 | 2013-09-23 13:53:13 -0500 | [diff] [blame] | 87 | } | 
|  | 88 |  | 
|  | 89 | # install_nova_hypervisor() - Install external components | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 90 | function install_nova_hypervisor { | 
| Adam Gandelman | 0f73ff2 | 2014-03-13 14:20:43 -0700 | [diff] [blame] | 91 | install_libvirt | 
| Dean Troyer | 8c032d1 | 2013-09-23 13:53:13 -0500 | [diff] [blame] | 92 |  | 
|  | 93 | # Install and configure **LXC** if specified.  LXC is another approach to | 
|  | 94 | # splitting a system into many smaller parts.  LXC uses cgroups and chroot | 
|  | 95 | # to simulate multiple systems. | 
|  | 96 | if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then | 
|  | 97 | if is_ubuntu; then | 
|  | 98 | if [[ "$DISTRO" > natty ]]; then | 
|  | 99 | install_package cgroup-lite | 
|  | 100 | fi | 
|  | 101 | else | 
|  | 102 | ### FIXME(dtroyer): figure this out | 
|  | 103 | echo "RPM-based cgroup not implemented yet" | 
|  | 104 | yum_install libcgroup-tools | 
|  | 105 | fi | 
|  | 106 | fi | 
| Matt Riedemann | 6390d5e | 2016-09-12 11:23:19 -0400 | [diff] [blame] | 107 |  | 
|  | 108 | if [[ "$ENABLE_FILE_INJECTION" == "True" ]] ; then | 
|  | 109 | if is_ubuntu; then | 
| Masayuki Igawa | 89acae9 | 2020-12-16 09:12:40 +0900 | [diff] [blame] | 110 | install_package python3-guestfs | 
| Andrea Frittoli | 1c442ee | 2016-11-30 20:44:44 +0000 | [diff] [blame] | 111 | # NOTE(andreaf) Ubuntu kernel can only be read by root, which breaks libguestfs: | 
|  | 112 | # https://bugs.launchpad.net/ubuntu/+source/linux/+bug/759725) | 
|  | 113 | INSTALLED_KERNELS="$(ls /boot/vmlinuz-*)" | 
|  | 114 | for kernel in $INSTALLED_KERNELS; do | 
|  | 115 | STAT_OVERRIDE="root root 644 ${kernel}" | 
|  | 116 | # unstack won't remove the statoverride, so make this idempotent | 
|  | 117 | if [[ ! $(dpkg-statoverride --list | grep "$STAT_OVERRIDE") ]]; then | 
|  | 118 | sudo dpkg-statoverride --add --update $STAT_OVERRIDE | 
|  | 119 | fi | 
|  | 120 | done | 
| Dirk Mueller | a6467d3 | 2017-06-27 08:31:26 +0200 | [diff] [blame] | 121 | elif is_suse; then | 
|  | 122 | # Workaround for missing dependencies in python-libguestfs | 
|  | 123 | install_package python-libguestfs guestfs-data augeas augeas-lenses | 
|  | 124 | elif is_fedora; then | 
| Ian Wienand | 9b8b702 | 2020-04-16 13:03:56 +1000 | [diff] [blame] | 125 | install_package python3-libguestfs | 
| Matt Riedemann | 6390d5e | 2016-09-12 11:23:19 -0400 | [diff] [blame] | 126 | fi | 
|  | 127 | fi | 
| Dean Troyer | 8c032d1 | 2013-09-23 13:53:13 -0500 | [diff] [blame] | 128 | } | 
|  | 129 |  | 
|  | 130 | # start_nova_hypervisor - Start any required external services | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 131 | function start_nova_hypervisor { | 
| Dean Troyer | 8c032d1 | 2013-09-23 13:53:13 -0500 | [diff] [blame] | 132 | # This function intentionally left blank | 
|  | 133 | : | 
|  | 134 | } | 
|  | 135 |  | 
|  | 136 | # stop_nova_hypervisor - Stop any external services | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 137 | function stop_nova_hypervisor { | 
| Dean Troyer | 8c032d1 | 2013-09-23 13:53:13 -0500 | [diff] [blame] | 138 | # This function intentionally left blank | 
|  | 139 | : | 
|  | 140 | } | 
|  | 141 |  | 
|  | 142 |  | 
|  | 143 | # Restore xtrace | 
| Ian Wienand | 523f488 | 2015-10-13 11:03:03 +1100 | [diff] [blame] | 144 | $_XTRACE_NOVA_LIBVIRT | 
| Dean Troyer | 8c032d1 | 2013-09-23 13:53:13 -0500 | [diff] [blame] | 145 |  | 
|  | 146 | # Local variables: | 
|  | 147 | # mode: shell-script | 
|  | 148 | # End: |