Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 1 | # lib/nova |
Dean Troyer | 6d04fd7 | 2012-12-21 11:03:37 -0600 | [diff] [blame] | 2 | # Functions to control the configuration and operation of the **Nova** service |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 3 | |
| 4 | # Dependencies: |
| 5 | # ``functions`` file |
Attila Fazekas | 91b8d13 | 2013-01-06 22:40:09 +0100 | [diff] [blame] | 6 | # ``DEST``, ``DATA_DIR``, ``STACK_USER`` must be defined |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 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 Troyer | bc071bc | 2012-10-01 14:06:44 -0500 | [diff] [blame] | 10 | # ``KEYSTONE_TOKEN_FORMAT`` must be defined |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 11 | |
| 12 | # ``stack.sh`` calls the entry points in this order: |
| 13 | # |
| 14 | # install_nova |
| 15 | # configure_nova |
Dean Troyer | da7b809 | 2012-10-08 18:12:14 -0500 | [diff] [blame] | 16 | # create_nova_conf |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 17 | # init_nova |
| 18 | # start_nova |
| 19 | # stop_nova |
| 20 | # cleanup_nova |
| 21 | |
| 22 | # Save trace setting |
| 23 | XTRACE=$(set +o | grep xtrace) |
| 24 | set +o xtrace |
| 25 | |
| 26 | |
| 27 | # Defaults |
| 28 | # -------- |
| 29 | |
| 30 | # Set up default directories |
| 31 | NOVA_DIR=$DEST/nova |
| 32 | NOVACLIENT_DIR=$DEST/python-novaclient |
| 33 | NOVA_STATE_PATH=${NOVA_STATE_PATH:=$DATA_DIR/nova} |
| 34 | # INSTANCES_PATH is the previous name for this |
| 35 | NOVA_INSTANCES_PATH=${NOVA_INSTANCES_PATH:=${INSTANCES_PATH:=$NOVA_STATE_PATH/instances}} |
Dean Troyer | bc071bc | 2012-10-01 14:06:44 -0500 | [diff] [blame] | 36 | NOVA_AUTH_CACHE_DIR=${NOVA_AUTH_CACHE_DIR:-/var/cache/nova} |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 37 | |
| 38 | NOVA_CONF_DIR=/etc/nova |
| 39 | NOVA_CONF=$NOVA_CONF_DIR/nova.conf |
Kieran Spear | fb2a3ae | 2013-03-11 23:55:49 +0000 | [diff] [blame] | 40 | NOVA_CELLS_CONF=$NOVA_CONF_DIR/nova-cells.conf |
| 41 | NOVA_CELLS_DB=${NOVA_CELLS_DB:-nova_cell} |
| 42 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 43 | NOVA_API_PASTE_INI=${NOVA_API_PASTE_INI:-$NOVA_CONF_DIR/api-paste.ini} |
| 44 | |
Dean Troyer | 3a3a2ba | 2012-12-11 15:26:24 -0600 | [diff] [blame] | 45 | # Public facing bits |
| 46 | NOVA_SERVICE_HOST=${NOVA_SERVICE_HOST:-$SERVICE_HOST} |
| 47 | NOVA_SERVICE_PORT=${NOVA_SERVICE_PORT:-8774} |
| 48 | NOVA_SERVICE_PORT_INT=${NOVA_SERVICE_PORT_INT:-18774} |
| 49 | NOVA_SERVICE_PROTOCOL=${NOVA_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL} |
| 50 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 51 | # Support entry points installation of console scripts |
| 52 | if [[ -d $NOVA_DIR/bin ]]; then |
| 53 | NOVA_BIN_DIR=$NOVA_DIR/bin |
| 54 | else |
Jakub Ruzicka | 4196d55 | 2013-01-30 15:35:54 +0100 | [diff] [blame] | 55 | NOVA_BIN_DIR=$(get_python_exec_prefix) |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 56 | fi |
| 57 | |
| 58 | # Set the paths of certain binaries |
Vincent Untz | 856a11e | 2012-11-21 16:04:12 +0100 | [diff] [blame] | 59 | NOVA_ROOTWRAP=$(get_rootwrap_location nova) |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 60 | |
| 61 | # Allow rate limiting to be turned off for testing, like for Tempest |
| 62 | # NOTE: Set API_RATE_LIMIT="False" to turn OFF rate limiting |
| 63 | API_RATE_LIMIT=${API_RATE_LIMIT:-"True"} |
| 64 | |
| 65 | # Nova supports pluggable schedulers. The default ``FilterScheduler`` |
| 66 | # should work in most cases. |
| 67 | SCHEDULER=${SCHEDULER:-nova.scheduler.filter_scheduler.FilterScheduler} |
| 68 | |
| 69 | QEMU_CONF=/etc/libvirt/qemu.conf |
| 70 | |
Dean Troyer | b7490da | 2013-03-18 16:07:56 -0500 | [diff] [blame] | 71 | NOVNC_DIR=$DEST/noVNC |
| 72 | SPICE_DIR=$DEST/spice-html5 |
| 73 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 74 | |
Dean Troyer | b323691 | 2013-03-17 15:17:05 -0500 | [diff] [blame] | 75 | # Nova Network Configuration |
| 76 | # -------------------------- |
| 77 | |
| 78 | # Set defaults according to the virt driver |
| 79 | if [ "$VIRT_DRIVER" = 'xenserver' ]; then |
Mate Lakat | 5a56cd6 | 2013-06-17 13:54:43 +0100 | [diff] [blame^] | 80 | PUBLIC_INTERFACE_DEFAULT=eth2 |
Dean Troyer | b323691 | 2013-03-17 15:17:05 -0500 | [diff] [blame] | 81 | GUEST_INTERFACE_DEFAULT=eth1 |
| 82 | # Allow ``build_domU.sh`` to specify the flat network bridge via kernel args |
Mate Lakat | f652e0f | 2013-05-21 18:12:48 +0100 | [diff] [blame] | 83 | FLAT_NETWORK_BRIDGE_DEFAULT=$(sed -e 's/.* flat_network_bridge=\([[:alnum:]]*\).*$/\1/g' /proc/cmdline) |
| 84 | if is_service_enabled quantum; then |
| 85 | XEN_INTEGRATION_BRIDGE=$(sed -e 's/.* xen_integration_bridge=\([[:alnum:]]*\).*$/\1/g' /proc/cmdline) |
| 86 | fi |
Dean Troyer | b323691 | 2013-03-17 15:17:05 -0500 | [diff] [blame] | 87 | elif [ "$VIRT_DRIVER" = 'baremetal' ]; then |
| 88 | NETWORK_MANAGER=${NETWORK_MANAGER:-FlatManager} |
| 89 | PUBLIC_INTERFACE_DEFAULT=eth0 |
| 90 | FLAT_INTERFACE=${FLAT_INTERFACE:-eth0} |
| 91 | FLAT_NETWORK_BRIDGE_DEFAULT=br100 |
| 92 | STUB_NETWORK=${STUB_NETWORK:-False} |
| 93 | else |
| 94 | PUBLIC_INTERFACE_DEFAULT=br100 |
| 95 | GUEST_INTERFACE_DEFAULT=eth0 |
| 96 | FLAT_NETWORK_BRIDGE_DEFAULT=br100 |
| 97 | fi |
| 98 | |
| 99 | NETWORK_MANAGER=${NETWORK_MANAGER:-${NET_MAN:-FlatDHCPManager}} |
| 100 | PUBLIC_INTERFACE=${PUBLIC_INTERFACE:-$PUBLIC_INTERFACE_DEFAULT} |
| 101 | VLAN_INTERFACE=${VLAN_INTERFACE:-$GUEST_INTERFACE_DEFAULT} |
| 102 | FLAT_NETWORK_BRIDGE=${FLAT_NETWORK_BRIDGE:-$FLAT_NETWORK_BRIDGE_DEFAULT} |
| 103 | EC2_DMZ_HOST=${EC2_DMZ_HOST:-$SERVICE_HOST} |
| 104 | |
| 105 | # If you are using the FlatDHCP network mode on multiple hosts, set the |
| 106 | # ``FLAT_INTERFACE`` variable but make sure that the interface doesn't already |
| 107 | # have an IP or you risk breaking things. |
| 108 | # |
| 109 | # **DHCP Warning**: If your flat interface device uses DHCP, there will be a |
| 110 | # hiccup while the network is moved from the flat interface to the flat network |
| 111 | # bridge. This will happen when you launch your first instance. Upon launch |
| 112 | # you will lose all connectivity to the node, and the VM launch will probably |
| 113 | # fail. |
| 114 | # |
| 115 | # If you are running on a single node and don't need to access the VMs from |
| 116 | # devices other than that node, you can set ``FLAT_INTERFACE=`` |
| 117 | # This will stop nova from bridging any interfaces into ``FLAT_NETWORK_BRIDGE``. |
Davanum Srinivas | b93b74c | 2013-03-21 21:25:05 -0400 | [diff] [blame] | 118 | FLAT_INTERFACE=${FLAT_INTERFACE:-$GUEST_INTERFACE_DEFAULT} |
Dean Troyer | b323691 | 2013-03-17 15:17:05 -0500 | [diff] [blame] | 119 | |
| 120 | # ``MULTI_HOST`` is a mode where each compute node runs its own network node. This |
| 121 | # allows network operations and routing for a VM to occur on the server that is |
| 122 | # running the VM - removing a SPOF and bandwidth bottleneck. |
| 123 | MULTI_HOST=`trueorfalse False $MULTI_HOST` |
| 124 | |
| 125 | # Test floating pool and range are used for testing. They are defined |
| 126 | # here until the admin APIs can replace nova-manage |
| 127 | TEST_FLOATING_POOL=${TEST_FLOATING_POOL:-test} |
| 128 | TEST_FLOATING_RANGE=${TEST_FLOATING_RANGE:-192.168.253.0/29} |
| 129 | |
| 130 | |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 131 | # Functions |
| 132 | # --------- |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 133 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 134 | # Helper to clean iptables rules |
| 135 | function clean_iptables() { |
| 136 | # Delete rules |
| 137 | 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 |
| 138 | # Delete nat rules |
| 139 | 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 |
| 140 | # Delete chains |
| 141 | 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 |
| 142 | # Delete nat chains |
| 143 | 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 |
| 144 | } |
| 145 | |
| 146 | # cleanup_nova() - Remove residual data files, anything left over from previous |
| 147 | # runs that a clean run would need to clean up |
| 148 | function cleanup_nova() { |
| 149 | if is_service_enabled n-cpu; then |
| 150 | # Clean iptables from previous runs |
| 151 | clean_iptables |
| 152 | |
| 153 | # Destroy old instances |
| 154 | instances=`sudo virsh list --all | grep $INSTANCE_NAME_PREFIX | sed "s/.*\($INSTANCE_NAME_PREFIX[0-9a-fA-F]*\).*/\1/g"` |
| 155 | if [ ! "$instances" = "" ]; then |
| 156 | echo $instances | xargs -n1 sudo virsh destroy || true |
Daniel P. Berrange | d52008a | 2013-05-20 15:03:43 +0100 | [diff] [blame] | 157 | echo $instances | xargs -n1 sudo virsh undefine --managed-save || true |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 158 | fi |
| 159 | |
| 160 | # Logout and delete iscsi sessions |
Dan Smith | c0fad2b | 2013-03-28 12:22:25 -0700 | [diff] [blame] | 161 | tgts=$(sudo iscsiadm --mode node | grep $VOLUME_NAME_PREFIX | cut -d ' ' -f2) |
| 162 | for target in $tgts; do |
| 163 | sudo iscsiadm --mode node -T $target --logout || true |
| 164 | done |
| 165 | sudo iscsiadm --mode node --op delete || true |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 166 | |
| 167 | # Clean out the instances directory. |
| 168 | sudo rm -rf $NOVA_INSTANCES_PATH/* |
| 169 | fi |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 170 | |
| 171 | sudo rm -rf $NOVA_STATE_PATH $NOVA_AUTH_CACHE_DIR |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 172 | } |
| 173 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 174 | # configure_nova_rootwrap() - configure Nova's rootwrap |
| 175 | function configure_nova_rootwrap() { |
| 176 | # Deploy new rootwrap filters files (owned by root). |
| 177 | # Wipe any existing rootwrap.d files first |
| 178 | if [[ -d $NOVA_CONF_DIR/rootwrap.d ]]; then |
| 179 | sudo rm -rf $NOVA_CONF_DIR/rootwrap.d |
| 180 | fi |
| 181 | # Deploy filters to /etc/nova/rootwrap.d |
| 182 | sudo mkdir -m 755 $NOVA_CONF_DIR/rootwrap.d |
| 183 | sudo cp $NOVA_DIR/etc/nova/rootwrap.d/*.filters $NOVA_CONF_DIR/rootwrap.d |
| 184 | sudo chown -R root:root $NOVA_CONF_DIR/rootwrap.d |
| 185 | sudo chmod 644 $NOVA_CONF_DIR/rootwrap.d/* |
| 186 | # Set up rootwrap.conf, pointing to /etc/nova/rootwrap.d |
| 187 | sudo cp $NOVA_DIR/etc/nova/rootwrap.conf $NOVA_CONF_DIR/ |
| 188 | sudo sed -e "s:^filters_path=.*$:filters_path=$NOVA_CONF_DIR/rootwrap.d:" -i $NOVA_CONF_DIR/rootwrap.conf |
| 189 | sudo chown root:root $NOVA_CONF_DIR/rootwrap.conf |
| 190 | sudo chmod 0644 $NOVA_CONF_DIR/rootwrap.conf |
| 191 | # Specify rootwrap.conf as first parameter to nova-rootwrap |
| 192 | ROOTWRAP_SUDOER_CMD="$NOVA_ROOTWRAP $NOVA_CONF_DIR/rootwrap.conf *" |
| 193 | |
| 194 | # Set up the rootwrap sudoers for nova |
| 195 | TEMPFILE=`mktemp` |
| 196 | echo "$USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE |
| 197 | chmod 0440 $TEMPFILE |
| 198 | sudo chown root:root $TEMPFILE |
| 199 | sudo mv $TEMPFILE /etc/sudoers.d/nova-rootwrap |
| 200 | } |
| 201 | |
| 202 | # configure_nova() - Set config files, create data dirs, etc |
| 203 | function configure_nova() { |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 204 | # Put config files in ``/etc/nova`` for everyone to find |
| 205 | if [[ ! -d $NOVA_CONF_DIR ]]; then |
| 206 | sudo mkdir -p $NOVA_CONF_DIR |
| 207 | fi |
Attila Fazekas | 91b8d13 | 2013-01-06 22:40:09 +0100 | [diff] [blame] | 208 | sudo chown $STACK_USER $NOVA_CONF_DIR |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 209 | |
| 210 | cp -p $NOVA_DIR/etc/nova/policy.json $NOVA_CONF_DIR |
| 211 | |
| 212 | configure_nova_rootwrap |
| 213 | |
| 214 | if is_service_enabled n-api; then |
| 215 | # Use the sample http middleware configuration supplied in the |
| 216 | # Nova sources. This paste config adds the configuration required |
| 217 | # for Nova to validate Keystone tokens. |
| 218 | |
| 219 | # Remove legacy paste config if present |
| 220 | rm -f $NOVA_DIR/bin/nova-api-paste.ini |
| 221 | |
| 222 | # Get the sample configuration file in place |
| 223 | cp $NOVA_DIR/etc/nova/api-paste.ini $NOVA_CONF_DIR |
| 224 | |
Mate Lakat | a6601a5 | 2013-03-13 13:35:47 +0000 | [diff] [blame] | 225 | iniset $NOVA_API_PASTE_INI filter:authtoken auth_host $KEYSTONE_AUTH_HOST |
Dean Troyer | 3a3a2ba | 2012-12-11 15:26:24 -0600 | [diff] [blame] | 226 | if is_service_enabled tls-proxy; then |
Mate Lakat | a6601a5 | 2013-03-13 13:35:47 +0000 | [diff] [blame] | 227 | iniset $NOVA_API_PASTE_INI filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL |
Dean Troyer | 3a3a2ba | 2012-12-11 15:26:24 -0600 | [diff] [blame] | 228 | fi |
Dean Troyer | b205cc8 | 2013-02-11 17:34:39 -0600 | [diff] [blame] | 229 | iniset $NOVA_API_PASTE_INI filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME |
| 230 | iniset $NOVA_API_PASTE_INI filter:authtoken admin_user nova |
| 231 | iniset $NOVA_API_PASTE_INI filter:authtoken admin_password $SERVICE_PASSWORD |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 232 | fi |
| 233 | |
Akihiro MOTOKI | 5e3deb6 | 2012-12-11 17:09:02 +0900 | [diff] [blame] | 234 | iniset $NOVA_API_PASTE_INI filter:authtoken signing_dir $NOVA_AUTH_CACHE_DIR |
Dean Troyer | bc071bc | 2012-10-01 14:06:44 -0500 | [diff] [blame] | 235 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 236 | if is_service_enabled n-cpu; then |
| 237 | # Force IP forwarding on, just on case |
| 238 | sudo sysctl -w net.ipv4.ip_forward=1 |
| 239 | |
Bob Ball | b1e49bf | 2013-05-30 16:47:19 +0100 | [diff] [blame] | 240 | if [[ "$VIRT_DRIVER" = 'libvirt' ]]; then |
| 241 | # Attempt to load modules: network block device - used to manage qcow images |
| 242 | sudo modprobe nbd || true |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 243 | |
Bob Ball | b1e49bf | 2013-05-30 16:47:19 +0100 | [diff] [blame] | 244 | # Check for kvm (hardware based virtualization). If unable to initialize |
| 245 | # kvm, we drop back to the slower emulation mode (qemu). Note: many systems |
| 246 | # come with hardware virtualization disabled in BIOS. |
| 247 | if [[ "$LIBVIRT_TYPE" == "kvm" ]]; then |
| 248 | sudo modprobe kvm || true |
| 249 | if [ ! -e /dev/kvm ]; then |
| 250 | echo "WARNING: Switching to QEMU" |
| 251 | LIBVIRT_TYPE=qemu |
| 252 | if which selinuxenabled 2>&1 > /dev/null && selinuxenabled; then |
| 253 | # https://bugzilla.redhat.com/show_bug.cgi?id=753589 |
| 254 | sudo setsebool virt_use_execmem on |
| 255 | fi |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 256 | fi |
| 257 | fi |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 258 | |
Bob Ball | b1e49bf | 2013-05-30 16:47:19 +0100 | [diff] [blame] | 259 | # Install and configure **LXC** if specified. LXC is another approach to |
| 260 | # splitting a system into many smaller parts. LXC uses cgroups and chroot |
| 261 | # to simulate multiple systems. |
| 262 | if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then |
| 263 | if is_ubuntu; then |
| 264 | if [[ ! "$DISTRO" > natty ]]; then |
| 265 | cgline="none /cgroup cgroup cpuacct,memory,devices,cpu,freezer,blkio 0 0" |
| 266 | sudo mkdir -p /cgroup |
| 267 | if ! grep -q cgroup /etc/fstab; then |
| 268 | echo "$cgline" | sudo tee -a /etc/fstab |
| 269 | fi |
| 270 | if ! mount -n | grep -q cgroup; then |
| 271 | sudo mount /cgroup |
| 272 | fi |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 273 | fi |
| 274 | fi |
| 275 | fi |
| 276 | fi |
| 277 | |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 278 | # Prepare directories and packages for baremetal driver |
| 279 | if is_baremetal; then |
| 280 | configure_baremetal_nova_dirs |
| 281 | fi |
| 282 | |
Bob Ball | b1e49bf | 2013-05-30 16:47:19 +0100 | [diff] [blame] | 283 | if [[ "$VIRT_DRIVER" = 'libvirt' ]]; then |
| 284 | if is_service_enabled quantum && is_quantum_ovs_base_plugin && ! sudo grep -q '^cgroup_device_acl' $QEMU_CONF; then |
| 285 | # Add /dev/net/tun to cgroup_device_acls, needed for type=ethernet interfaces |
| 286 | cat <<EOF | sudo tee -a $QEMU_CONF |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 287 | cgroup_device_acl = [ |
| 288 | "/dev/null", "/dev/full", "/dev/zero", |
| 289 | "/dev/random", "/dev/urandom", |
| 290 | "/dev/ptmx", "/dev/kvm", "/dev/kqemu", |
| 291 | "/dev/rtc", "/dev/hpet","/dev/net/tun", |
| 292 | ] |
| 293 | EOF |
Bob Ball | b1e49bf | 2013-05-30 16:47:19 +0100 | [diff] [blame] | 294 | fi |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 295 | |
Bob Ball | b1e49bf | 2013-05-30 16:47:19 +0100 | [diff] [blame] | 296 | if is_ubuntu; then |
| 297 | LIBVIRT_DAEMON=libvirt-bin |
| 298 | else |
| 299 | LIBVIRT_DAEMON=libvirtd |
| 300 | fi |
Vincent Untz | f1c094c | 2012-12-05 17:59:04 +0100 | [diff] [blame] | 301 | |
Bob Ball | b1e49bf | 2013-05-30 16:47:19 +0100 | [diff] [blame] | 302 | if is_fedora || is_suse; then |
Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 303 | if is_fedora && [[ $DISTRO =~ (rhel6) || "$os_RELEASE" -le "17" ]]; then |
Bob Ball | b1e49bf | 2013-05-30 16:47:19 +0100 | [diff] [blame] | 304 | sudo bash -c "cat <<EOF >/etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla |
Ralf Haferkamp | 76ca9a9 | 2013-04-12 12:39:58 +0200 | [diff] [blame] | 305 | [libvirt Management Access] |
Émilien Macchi | b2ef890 | 2013-05-04 00:48:20 +0200 | [diff] [blame] | 306 | Identity=unix-group:$LIBVIRT_GROUP |
Ralf Haferkamp | 76ca9a9 | 2013-04-12 12:39:58 +0200 | [diff] [blame] | 307 | Action=org.libvirt.unix.manage |
| 308 | ResultAny=yes |
| 309 | ResultInactive=yes |
| 310 | ResultActive=yes |
Émilien Macchi | b2ef890 | 2013-05-04 00:48:20 +0200 | [diff] [blame] | 311 | EOF" |
Bob Ball | b1e49bf | 2013-05-30 16:47:19 +0100 | [diff] [blame] | 312 | elif is_suse && [[ $os_RELEASE = 12.2 || "$os_VENDOR" = "SUSE LINUX" ]]; then |
| 313 | # openSUSE < 12.3 or SLE |
| 314 | # Work around the fact that polkit-default-privs overrules pklas |
| 315 | # with 'unix-group:$group'. |
| 316 | sudo bash -c "cat <<EOF >/etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla |
Ralf Haferkamp | 76ca9a9 | 2013-04-12 12:39:58 +0200 | [diff] [blame] | 317 | [libvirt Management Access] |
| 318 | Identity=unix-user:$USER |
| 319 | Action=org.libvirt.unix.manage |
| 320 | ResultAny=yes |
| 321 | ResultInactive=yes |
| 322 | ResultActive=yes |
| 323 | EOF" |
Bob Ball | b1e49bf | 2013-05-30 16:47:19 +0100 | [diff] [blame] | 324 | else |
| 325 | # Starting with fedora 18 and opensuse-12.3 enable stack-user to |
| 326 | # virsh -c qemu:///system by creating a policy-kit rule for |
| 327 | # stack-user using the new Javascript syntax |
| 328 | rules_dir=/etc/polkit-1/rules.d |
| 329 | sudo mkdir -p $rules_dir |
| 330 | sudo bash -c "cat <<EOF > $rules_dir/50-libvirt-$STACK_USER.rules |
Sunil Thaha | a534e0b | 2013-01-21 17:00:50 +1000 | [diff] [blame] | 331 | polkit.addRule(function(action, subject) { |
| 332 | if (action.id == 'org.libvirt.unix.manage' && |
| 333 | subject.user == '"$STACK_USER"') { |
| 334 | return polkit.Result.YES; |
| 335 | } |
| 336 | }); |
| 337 | EOF" |
Bob Ball | b1e49bf | 2013-05-30 16:47:19 +0100 | [diff] [blame] | 338 | unset rules_dir |
| 339 | fi |
Sunil Thaha | a534e0b | 2013-01-21 17:00:50 +1000 | [diff] [blame] | 340 | fi |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 341 | |
Bob Ball | b1e49bf | 2013-05-30 16:47:19 +0100 | [diff] [blame] | 342 | # The user that nova runs as needs to be member of **libvirtd** group otherwise |
| 343 | # nova-compute will be unable to use libvirt. |
| 344 | if ! getent group $LIBVIRT_GROUP >/dev/null; then |
| 345 | sudo groupadd $LIBVIRT_GROUP |
| 346 | fi |
| 347 | add_user_to_group $STACK_USER $LIBVIRT_GROUP |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 348 | |
Bob Ball | b1e49bf | 2013-05-30 16:47:19 +0100 | [diff] [blame] | 349 | # libvirt detects various settings on startup, as we potentially changed |
| 350 | # the system configuration (modules, filesystems), we need to restart |
| 351 | # libvirt to detect those changes. |
| 352 | restart_service $LIBVIRT_DAEMON |
| 353 | fi |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 354 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 355 | # Instance Storage |
| 356 | # ---------------- |
| 357 | |
| 358 | # Nova stores each instance in its own directory. |
Doug Hellmann | cf9eef8 | 2013-03-25 19:34:48 -0400 | [diff] [blame] | 359 | sudo mkdir -p $NOVA_INSTANCES_PATH |
| 360 | sudo chown -R $STACK_USER $NOVA_INSTANCES_PATH |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 361 | |
| 362 | # You can specify a different disk to be mounted and used for backing the |
| 363 | # virtual machines. If there is a partition labeled nova-instances we |
| 364 | # mount it (ext filesystems can be labeled via e2label). |
| 365 | if [ -L /dev/disk/by-label/nova-instances ]; then |
| 366 | if ! mount -n | grep -q $NOVA_INSTANCES_PATH; then |
| 367 | sudo mount -L nova-instances $NOVA_INSTANCES_PATH |
Attila Fazekas | 91b8d13 | 2013-01-06 22:40:09 +0100 | [diff] [blame] | 368 | sudo chown -R $STACK_USER $NOVA_INSTANCES_PATH |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 369 | fi |
| 370 | fi |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 371 | fi |
| 372 | } |
| 373 | |
Dean Troyer | a0dce26 | 2012-12-11 16:52:37 -0600 | [diff] [blame] | 374 | # create_nova_accounts() - Set up common required nova accounts |
| 375 | |
| 376 | # Tenant User Roles |
| 377 | # ------------------------------------------------------------------ |
| 378 | # service nova admin, [ResellerAdmin (swift only)] |
| 379 | |
| 380 | # Migrated from keystone_data.sh |
| 381 | create_nova_accounts() { |
| 382 | |
| 383 | SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }") |
| 384 | ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }") |
| 385 | |
| 386 | # Nova |
| 387 | if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then |
| 388 | NOVA_USER=$(keystone user-create \ |
| 389 | --name=nova \ |
| 390 | --pass="$SERVICE_PASSWORD" \ |
| 391 | --tenant_id $SERVICE_TENANT \ |
| 392 | --email=nova@example.com \ |
| 393 | | grep " id " | get_field 2) |
| 394 | keystone user-role-add \ |
| 395 | --tenant_id $SERVICE_TENANT \ |
| 396 | --user_id $NOVA_USER \ |
| 397 | --role_id $ADMIN_ROLE |
| 398 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then |
| 399 | NOVA_SERVICE=$(keystone service-create \ |
| 400 | --name=nova \ |
| 401 | --type=compute \ |
| 402 | --description="Nova Compute Service" \ |
| 403 | | grep " id " | get_field 2) |
| 404 | keystone endpoint-create \ |
| 405 | --region RegionOne \ |
| 406 | --service_id $NOVA_SERVICE \ |
Dean Troyer | 3a3a2ba | 2012-12-11 15:26:24 -0600 | [diff] [blame] | 407 | --publicurl "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2/\$(tenant_id)s" \ |
| 408 | --adminurl "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2/\$(tenant_id)s" \ |
| 409 | --internalurl "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2/\$(tenant_id)s" |
Dean Troyer | a0dce26 | 2012-12-11 16:52:37 -0600 | [diff] [blame] | 410 | fi |
| 411 | fi |
| 412 | } |
| 413 | |
Dean Troyer | da7b809 | 2012-10-08 18:12:14 -0500 | [diff] [blame] | 414 | # create_nova_conf() - Create a new nova.conf file |
| 415 | function create_nova_conf() { |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 416 | # Remove legacy ``nova.conf`` |
| 417 | rm -f $NOVA_DIR/bin/nova.conf |
| 418 | |
| 419 | # (Re)create ``nova.conf`` |
Dean Troyer | 3cf1ffb | 2012-10-02 11:51:27 -0500 | [diff] [blame] | 420 | rm -f $NOVA_CONF |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 421 | iniset $NOVA_CONF DEFAULT verbose "True" |
Joe Gordon | 8750b3d | 2013-01-17 23:49:50 -0500 | [diff] [blame] | 422 | iniset $NOVA_CONF DEFAULT debug "True" |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 423 | iniset $NOVA_CONF DEFAULT auth_strategy "keystone" |
| 424 | iniset $NOVA_CONF DEFAULT allow_resize_to_same_host "True" |
| 425 | iniset $NOVA_CONF DEFAULT api_paste_config "$NOVA_API_PASTE_INI" |
| 426 | iniset $NOVA_CONF DEFAULT rootwrap_config "$NOVA_CONF_DIR/rootwrap.conf" |
| 427 | iniset $NOVA_CONF DEFAULT compute_scheduler_driver "$SCHEDULER" |
| 428 | iniset $NOVA_CONF DEFAULT dhcpbridge_flagfile "$NOVA_CONF" |
| 429 | iniset $NOVA_CONF DEFAULT force_dhcp_release "True" |
mathrock | 27c0695 | 2013-03-13 00:23:18 -0400 | [diff] [blame] | 430 | iniset $NOVA_CONF DEFAULT fixed_range "" |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 431 | iniset $NOVA_CONF DEFAULT default_floating_pool "$PUBLIC_NETWORK_NAME" |
| 432 | iniset $NOVA_CONF DEFAULT s3_host "$SERVICE_HOST" |
| 433 | iniset $NOVA_CONF DEFAULT s3_port "$S3_SERVICE_PORT" |
| 434 | iniset $NOVA_CONF DEFAULT osapi_compute_extension "nova.api.openstack.compute.contrib.standard_extensions" |
| 435 | iniset $NOVA_CONF DEFAULT my_ip "$HOST_IP" |
Attila Fazekas | 7e79d91 | 2013-03-03 12:23:04 +0100 | [diff] [blame] | 436 | iniset $NOVA_CONF DEFAULT sql_connection `database_connection_url nova` |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 437 | if is_baremetal; then |
Attila Fazekas | 7e79d91 | 2013-03-03 12:23:04 +0100 | [diff] [blame] | 438 | iniset $NOVA_CONF baremetal sql_connection `database_connection_url nova_bm` |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 439 | fi |
Bob Ball | b1e49bf | 2013-05-30 16:47:19 +0100 | [diff] [blame] | 440 | if [[ "$VIRT_DRIVER" = 'libvirt' ]]; then |
| 441 | iniset $NOVA_CONF DEFAULT libvirt_type "$LIBVIRT_TYPE" |
| 442 | iniset $NOVA_CONF DEFAULT libvirt_cpu_mode "none" |
| 443 | fi |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 444 | iniset $NOVA_CONF DEFAULT instance_name_template "${INSTANCE_NAME_PREFIX}%08x" |
Chris Yeoh | 1b4d91b | 2013-06-03 16:23:01 +0930 | [diff] [blame] | 445 | iniset $NOVA_CONF osapi_v3 enabled "True" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 446 | |
Ian Wienand | 00fd79d | 2013-06-06 11:19:16 +1000 | [diff] [blame] | 447 | if is_fedora; then |
| 448 | # nova defaults to /usr/local/bin, but fedora pip likes to |
| 449 | # install things in /usr/bin |
| 450 | iniset $NOVA_CONF DEFAULT bindir "/usr/bin" |
| 451 | fi |
| 452 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 453 | if is_service_enabled n-api; then |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 454 | iniset $NOVA_CONF DEFAULT enabled_apis "$NOVA_ENABLED_APIS" |
Dean Troyer | 3a3a2ba | 2012-12-11 15:26:24 -0600 | [diff] [blame] | 455 | if is_service_enabled tls-proxy; then |
| 456 | # Set the service port for a proxy to take the original |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 457 | iniset $NOVA_CONF DEFAULT osapi_compute_listen_port "$NOVA_SERVICE_PORT_INT" |
Dean Troyer | 3a3a2ba | 2012-12-11 15:26:24 -0600 | [diff] [blame] | 458 | fi |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 459 | fi |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 460 | if is_service_enabled cinder; then |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 461 | iniset $NOVA_CONF DEFAULT volume_api_class "nova.volume.cinder.API" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 462 | fi |
| 463 | if [ -n "$NOVA_STATE_PATH" ]; then |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 464 | iniset $NOVA_CONF DEFAULT state_path "$NOVA_STATE_PATH" |
| 465 | iniset $NOVA_CONF DEFAULT lock_path "$NOVA_STATE_PATH" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 466 | fi |
| 467 | if [ -n "$NOVA_INSTANCES_PATH" ]; then |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 468 | iniset $NOVA_CONF DEFAULT instances_path "$NOVA_INSTANCES_PATH" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 469 | fi |
| 470 | if [ "$MULTI_HOST" != "False" ]; then |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 471 | iniset $NOVA_CONF DEFAULT multi_host "True" |
| 472 | iniset $NOVA_CONF DEFAULT send_arp_for_ha "True" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 473 | fi |
| 474 | if [ "$SYSLOG" != "False" ]; then |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 475 | iniset $NOVA_CONF DEFAULT use_syslog "True" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 476 | fi |
| 477 | if [ "$API_RATE_LIMIT" != "True" ]; then |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 478 | iniset $NOVA_CONF DEFAULT api_rate_limit "False" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 479 | fi |
| 480 | if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then |
| 481 | # Add color to logging output |
Joe Gordon | 07db713 | 2013-01-30 13:07:25 -0800 | [diff] [blame] | 482 | iniset $NOVA_CONF DEFAULT logging_context_format_string "%(asctime)s.%(msecs)03d %(color)s%(levelname)s %(name)s [[01;36m%(request_id)s [00;36m%(user_name)s %(project_name)s%(color)s] [01;35m%(instance)s%(color)s%(message)s[00m" |
| 483 | iniset $NOVA_CONF DEFAULT logging_default_format_string "%(asctime)s.%(msecs)03d %(color)s%(levelname)s %(name)s [[00;36m-%(color)s] [01;35m%(instance)s%(color)s%(message)s[00m" |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 484 | iniset $NOVA_CONF DEFAULT logging_debug_format_suffix "[00;33mfrom (pid=%(process)d) %(funcName)s %(pathname)s:%(lineno)d[00m" |
Joe Gordon | 07db713 | 2013-01-30 13:07:25 -0800 | [diff] [blame] | 485 | iniset $NOVA_CONF DEFAULT logging_exception_prefix "%(color)s%(asctime)s.%(msecs)03d TRACE %(name)s [01;35m%(instance)s[00m" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 486 | else |
| 487 | # Show user_name and project_name instead of user_id and project_id |
Joe Gordon | 07db713 | 2013-01-30 13:07:25 -0800 | [diff] [blame] | 488 | iniset $NOVA_CONF DEFAULT logging_context_format_string "%(asctime)s.%(msecs)03d %(levelname)s %(name)s [%(request_id)s %(user_name)s %(project_name)s] %(instance)s%(message)s" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 489 | fi |
Eoghan Glynn | 1fcc6a1 | 2012-10-25 14:57:14 +0000 | [diff] [blame] | 490 | if is_service_enabled ceilometer; then |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 491 | iniset $NOVA_CONF DEFAULT instance_usage_audit "True" |
| 492 | iniset $NOVA_CONF DEFAULT instance_usage_audit_period "hour" |
Lianhao Lu | 239f324 | 2013-03-01 15:54:02 +0800 | [diff] [blame] | 493 | iniset_multiline $NOVA_CONF DEFAULT notification_driver "nova.openstack.common.notifier.rpc_notifier" "ceilometer.compute.nova_notifier" |
Eoghan Glynn | 1fcc6a1 | 2012-10-25 14:57:14 +0000 | [diff] [blame] | 494 | fi |
| 495 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 496 | # Provide some transition from ``EXTRA_FLAGS`` to ``EXTRA_OPTS`` |
| 497 | if [[ -z "$EXTRA_OPTS" && -n "$EXTRA_FLAGS" ]]; then |
| 498 | EXTRA_OPTS=$EXTRA_FLAGS |
| 499 | fi |
| 500 | |
| 501 | # Define extra nova conf flags by defining the array ``EXTRA_OPTS``. |
| 502 | # For Example: ``EXTRA_OPTS=(foo=true bar=2)`` |
| 503 | for I in "${EXTRA_OPTS[@]}"; do |
Dean Troyer | dff9512 | 2013-01-10 20:51:28 -0600 | [diff] [blame] | 504 | # Replace the first '=' with ' ' for iniset syntax |
| 505 | iniset $NOVA_CONF DEFAULT ${I/=/ } |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 506 | done |
Dean Troyer | b323691 | 2013-03-17 15:17:05 -0500 | [diff] [blame] | 507 | |
| 508 | # All nova-compute workers need to know the vnc configuration options |
| 509 | # These settings don't hurt anything if n-xvnc and n-novnc are disabled |
| 510 | if is_service_enabled n-cpu; then |
| 511 | NOVNCPROXY_URL=${NOVNCPROXY_URL:-"http://$SERVICE_HOST:6080/vnc_auto.html"} |
| 512 | iniset $NOVA_CONF DEFAULT novncproxy_base_url "$NOVNCPROXY_URL" |
| 513 | XVPVNCPROXY_URL=${XVPVNCPROXY_URL:-"http://$SERVICE_HOST:6081/console"} |
| 514 | iniset $NOVA_CONF DEFAULT xvpvncproxy_base_url "$XVPVNCPROXY_URL" |
| 515 | SPICEHTML5PROXY_URL=${SPICEHTML5PROXY_URL:-"http://$SERVICE_HOST:6082/spice_auto.html"} |
| 516 | iniset $NOVA_CONF spice html5proxy_base_url "$SPICEHTML5PROXY_URL" |
| 517 | fi |
| 518 | if [ "$VIRT_DRIVER" = 'xenserver' ]; then |
| 519 | VNCSERVER_PROXYCLIENT_ADDRESS=${VNCSERVER_PROXYCLIENT_ADDRESS=169.254.0.1} |
| 520 | else |
| 521 | VNCSERVER_PROXYCLIENT_ADDRESS=${VNCSERVER_PROXYCLIENT_ADDRESS=127.0.0.1} |
| 522 | fi |
| 523 | |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 524 | if is_service_enabled n-novnc || is_service_enabled n-xvnc; then |
Dean Troyer | b323691 | 2013-03-17 15:17:05 -0500 | [diff] [blame] | 525 | # Address on which instance vncservers will listen on compute hosts. |
| 526 | # For multi-host, this should be the management ip of the compute host. |
| 527 | VNCSERVER_LISTEN=${VNCSERVER_LISTEN=127.0.0.1} |
| 528 | iniset $NOVA_CONF DEFAULT vnc_enabled true |
| 529 | iniset $NOVA_CONF DEFAULT vncserver_listen "$VNCSERVER_LISTEN" |
| 530 | iniset $NOVA_CONF DEFAULT vncserver_proxyclient_address "$VNCSERVER_PROXYCLIENT_ADDRESS" |
| 531 | else |
| 532 | iniset $NOVA_CONF DEFAULT vnc_enabled false |
| 533 | fi |
| 534 | |
| 535 | if is_service_enabled n-spice; then |
| 536 | # Address on which instance spiceservers will listen on compute hosts. |
| 537 | # For multi-host, this should be the management ip of the compute host. |
| 538 | SPICESERVER_PROXYCLIENT_ADDRESS=${SPICESERVER_PROXYCLIENT_ADDRESS=127.0.0.1} |
| 539 | SPICESERVER_LISTEN=${SPICESERVER_LISTEN=127.0.0.1} |
| 540 | iniset $NOVA_CONF spice enabled true |
| 541 | iniset $NOVA_CONF spice server_listen "$SPICESERVER_LISTEN" |
| 542 | iniset $NOVA_CONF spice server_proxyclient_address "$SPICESERVER_PROXYCLIENT_ADDRESS" |
| 543 | else |
| 544 | iniset $NOVA_CONF spice enabled false |
| 545 | fi |
| 546 | |
| 547 | iniset $NOVA_CONF DEFAULT ec2_dmz_host "$EC2_DMZ_HOST" |
| 548 | iniset_rpc_backend nova $NOVA_CONF DEFAULT |
| 549 | iniset $NOVA_CONF DEFAULT glance_api_servers "$GLANCE_HOSTPORT" |
Dean Troyer | da7b809 | 2012-10-08 18:12:14 -0500 | [diff] [blame] | 550 | } |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 551 | |
Kieran Spear | fb2a3ae | 2013-03-11 23:55:49 +0000 | [diff] [blame] | 552 | function init_nova_cells() { |
| 553 | if is_service_enabled n-cell; then |
| 554 | cp $NOVA_CONF $NOVA_CELLS_CONF |
| 555 | iniset $NOVA_CELLS_CONF DEFAULT sql_connection `database_connection_url $NOVA_CELLS_DB` |
| 556 | iniset $NOVA_CELLS_CONF DEFAULT rabbit_virtual_host child_cell |
| 557 | iniset $NOVA_CELLS_CONF DEFAULT dhcpbridge_flagfile $NOVA_CELLS_CONF |
| 558 | iniset $NOVA_CELLS_CONF cells enable True |
| 559 | iniset $NOVA_CELLS_CONF cells name child |
| 560 | |
| 561 | iniset $NOVA_CONF DEFAULT scheduler_topic cells |
| 562 | iniset $NOVA_CONF DEFAULT compute_api_class nova.compute.cells_api.ComputeCellsAPI |
| 563 | iniset $NOVA_CONF cells enable True |
| 564 | iniset $NOVA_CONF cells name region |
| 565 | |
| 566 | if is_service_enabled n-api-meta; then |
| 567 | NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/,metadata//") |
| 568 | iniset $NOVA_CONF DEFAULT enabled_apis $NOVA_ENABLED_APIS |
| 569 | iniset $NOVA_CELLS_CONF DEFAULT enabled_apis metadata |
| 570 | fi |
| 571 | |
| 572 | $NOVA_BIN_DIR/nova-manage --config-file $NOVA_CELLS_CONF db sync |
| 573 | $NOVA_BIN_DIR/nova-manage --config-file $NOVA_CELLS_CONF cell create --name=region --cell_type=parent --username=guest --hostname=$RABBIT_HOST --port=5672 --password=$RABBIT_PASSWORD --virtual_host=/ --woffset=0 --wscale=1 |
| 574 | $NOVA_BIN_DIR/nova-manage cell create --name=child --cell_type=child --username=guest --hostname=$RABBIT_HOST --port=5672 --password=$RABBIT_PASSWORD --virtual_host=child_cell --woffset=0 --wscale=1 |
| 575 | fi |
| 576 | } |
| 577 | |
Dean Troyer | f03bafe | 2013-02-12 10:58:28 -0600 | [diff] [blame] | 578 | # create_nova_cache_dir() - Part of the init_nova() process |
| 579 | function create_nova_cache_dir() { |
| 580 | # Create cache dir |
| 581 | sudo mkdir -p $NOVA_AUTH_CACHE_DIR |
| 582 | sudo chown $STACK_USER $NOVA_AUTH_CACHE_DIR |
| 583 | rm -f $NOVA_AUTH_CACHE_DIR/* |
| 584 | } |
| 585 | |
Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 586 | function create_nova_conf_nova_network() { |
Dean Troyer | b323691 | 2013-03-17 15:17:05 -0500 | [diff] [blame] | 587 | iniset $NOVA_CONF DEFAULT network_manager "nova.network.manager.$NETWORK_MANAGER" |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 588 | iniset $NOVA_CONF DEFAULT public_interface "$PUBLIC_INTERFACE" |
| 589 | iniset $NOVA_CONF DEFAULT vlan_interface "$VLAN_INTERFACE" |
| 590 | iniset $NOVA_CONF DEFAULT flat_network_bridge "$FLAT_NETWORK_BRIDGE" |
Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 591 | if [ -n "$FLAT_INTERFACE" ]; then |
Devananda van der Veen | 9bc47db | 2012-12-12 16:52:55 -0800 | [diff] [blame] | 592 | iniset $NOVA_CONF DEFAULT flat_interface "$FLAT_INTERFACE" |
Akihiro MOTOKI | 66afb47 | 2012-12-21 15:34:13 +0900 | [diff] [blame] | 593 | fi |
| 594 | } |
| 595 | |
Dean Troyer | f03bafe | 2013-02-12 10:58:28 -0600 | [diff] [blame] | 596 | # create_nova_keys_dir() - Part of the init_nova() process |
| 597 | function create_nova_keys_dir() { |
| 598 | # Create keys dir |
| 599 | sudo mkdir -p ${NOVA_STATE_PATH}/keys |
| 600 | sudo chown -R $STACK_USER ${NOVA_STATE_PATH} |
| 601 | } |
| 602 | |
Dean Troyer | da7b809 | 2012-10-08 18:12:14 -0500 | [diff] [blame] | 603 | # init_nova() - Initialize databases, etc. |
| 604 | function init_nova() { |
Dean Troyer | f03bafe | 2013-02-12 10:58:28 -0600 | [diff] [blame] | 605 | # All nova components talk to a central database. |
| 606 | # Only do this step once on the API node for an entire cluster. |
Bob Melander | c439b5d | 2012-12-19 14:49:34 +0100 | [diff] [blame] | 607 | if is_service_enabled $DATABASE_BACKENDS && is_service_enabled n-api; then |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 608 | # (Re)create nova database |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 609 | # Explicitly use latin1: to avoid lp#829209, nova expects the database to |
| 610 | # use latin1 by default, and then upgrades the database to utf8 (see the |
| 611 | # 082_essex.py in nova) |
Terry Wilson | 428af5a | 2012-11-01 16:12:39 -0400 | [diff] [blame] | 612 | recreate_database nova latin1 |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 613 | |
Dean Troyer | f03bafe | 2013-02-12 10:58:28 -0600 | [diff] [blame] | 614 | # Migrate nova database |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 615 | $NOVA_BIN_DIR/nova-manage db sync |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 616 | |
Kieran Spear | fb2a3ae | 2013-03-11 23:55:49 +0000 | [diff] [blame] | 617 | if is_service_enabled n-cell; then |
| 618 | recreate_database $NOVA_CELLS_DB latin1 |
| 619 | fi |
| 620 | |
Devananda van der Veen | f35cf91 | 2012-11-12 17:58:38 -0800 | [diff] [blame] | 621 | # (Re)create nova baremetal database |
| 622 | if is_baremetal; then |
| 623 | recreate_database nova_bm latin1 |
| 624 | $NOVA_BIN_DIR/nova-baremetal-manage db sync |
| 625 | fi |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 626 | fi |
| 627 | |
Dean Troyer | f03bafe | 2013-02-12 10:58:28 -0600 | [diff] [blame] | 628 | create_nova_cache_dir |
| 629 | create_nova_keys_dir |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | # install_novaclient() - Collect source and prepare |
| 633 | function install_novaclient() { |
| 634 | git_clone $NOVACLIENT_REPO $NOVACLIENT_DIR $NOVACLIENT_BRANCH |
Dean Troyer | 253a1a3 | 2013-04-01 18:23:22 -0500 | [diff] [blame] | 635 | setup_develop $NOVACLIENT_DIR |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | # install_nova() - Collect source and prepare |
| 639 | function install_nova() { |
| 640 | if is_service_enabled n-cpu; then |
Bob Ball | b1e49bf | 2013-05-30 16:47:19 +0100 | [diff] [blame] | 641 | if [[ "$VIRT_DRIVER" = 'libvirt' ]]; then |
Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 642 | if is_ubuntu; then |
Bob Ball | b1e49bf | 2013-05-30 16:47:19 +0100 | [diff] [blame] | 643 | install_package kvm |
| 644 | install_package libvirt-bin |
| 645 | install_package python-libvirt |
| 646 | elif is_fedora || is_suse; then |
| 647 | install_package kvm |
| 648 | install_package libvirt |
| 649 | install_package libvirt-python |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 650 | else |
Bob Ball | b1e49bf | 2013-05-30 16:47:19 +0100 | [diff] [blame] | 651 | exit_distro_not_supported "libvirt installation" |
| 652 | fi |
| 653 | |
| 654 | # Install and configure **LXC** if specified. LXC is another approach to |
| 655 | # splitting a system into many smaller parts. LXC uses cgroups and chroot |
| 656 | # to simulate multiple systems. |
| 657 | if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then |
| 658 | if is_ubuntu; then |
| 659 | if [[ "$DISTRO" > natty ]]; then |
| 660 | install_package cgroup-lite |
| 661 | fi |
| 662 | else |
| 663 | ### FIXME(dtroyer): figure this out |
| 664 | echo "RPM-based cgroup not implemented yet" |
| 665 | yum_install libcgroup-tools |
| 666 | fi |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 667 | fi |
| 668 | fi |
| 669 | fi |
| 670 | |
| 671 | git_clone $NOVA_REPO $NOVA_DIR $NOVA_BRANCH |
Dean Troyer | 253a1a3 | 2013-04-01 18:23:22 -0500 | [diff] [blame] | 672 | setup_develop $NOVA_DIR |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 673 | } |
| 674 | |
Dean Troyer | 3a3a2ba | 2012-12-11 15:26:24 -0600 | [diff] [blame] | 675 | # start_nova_api() - Start the API process ahead of other things |
| 676 | function start_nova_api() { |
| 677 | # Get right service port for testing |
| 678 | local service_port=$NOVA_SERVICE_PORT |
| 679 | if is_service_enabled tls-proxy; then |
| 680 | service_port=$NOVA_SERVICE_PORT_INT |
| 681 | fi |
| 682 | |
| 683 | screen_it n-api "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-api" |
| 684 | echo "Waiting for nova-api to start..." |
| 685 | if ! wait_for_service $SERVICE_TIMEOUT http://$SERVICE_HOST:$service_port; then |
Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 686 | die $LINENO "nova-api did not start" |
Dean Troyer | 3a3a2ba | 2012-12-11 15:26:24 -0600 | [diff] [blame] | 687 | fi |
| 688 | |
| 689 | # Start proxies if enabled |
| 690 | if is_service_enabled tls-proxy; then |
| 691 | start_tls_proxy '*' $NOVA_SERVICE_PORT $NOVA_SERVICE_HOST $NOVA_SERVICE_PORT_INT & |
| 692 | fi |
| 693 | } |
| 694 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 695 | # start_nova() - Start running processes, including screen |
| 696 | function start_nova() { |
Kieran Spear | fb2a3ae | 2013-03-11 23:55:49 +0000 | [diff] [blame] | 697 | NOVA_CONF_BOTTOM=$NOVA_CONF |
| 698 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 699 | # ``screen_it`` checks ``is_service_enabled``, it is not needed here |
Russell Bryant | ff7f308 | 2012-11-29 22:00:51 -0500 | [diff] [blame] | 700 | screen_it n-cond "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-conductor" |
Kieran Spear | fb2a3ae | 2013-03-11 23:55:49 +0000 | [diff] [blame] | 701 | |
| 702 | if is_service_enabled n-cell; then |
| 703 | NOVA_CONF_BOTTOM=$NOVA_CELLS_CONF |
| 704 | screen_it n-cond "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-conductor --config-file $NOVA_CELLS_CONF" |
| 705 | screen_it n-cell "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-cells --config-file $NOVA_CONF" |
| 706 | screen_it n-cell "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-cells --config-file $NOVA_CELLS_CONF" |
| 707 | fi |
| 708 | |
Bob Ball | b1e49bf | 2013-05-30 16:47:19 +0100 | [diff] [blame] | 709 | if [[ "$VIRT_DRIVER" = 'libvirt' ]]; then |
| 710 | # The group **$LIBVIRT_GROUP** is added to the current user in this script. |
| 711 | # Use 'sg' to execute nova-compute as a member of the **$LIBVIRT_GROUP** group. |
| 712 | screen_it n-cpu "cd $NOVA_DIR && sg $LIBVIRT_GROUP '$NOVA_BIN_DIR/nova-compute --config-file $NOVA_CONF_BOTTOM'" |
| 713 | else |
| 714 | screen_it n-cpu "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-compute --config-file $NOVA_CONF_BOTTOM" |
| 715 | fi |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 716 | screen_it n-crt "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-cert" |
Kieran Spear | fb2a3ae | 2013-03-11 23:55:49 +0000 | [diff] [blame] | 717 | screen_it n-net "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-network --config-file $NOVA_CONF_BOTTOM" |
| 718 | screen_it n-sch "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-scheduler --config-file $NOVA_CONF_BOTTOM" |
| 719 | screen_it n-api-meta "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-api-metadata --config-file $NOVA_CONF_BOTTOM" |
| 720 | |
Daniel P. Berrange | 3edddd1 | 2013-01-03 12:06:47 +0000 | [diff] [blame] | 721 | screen_it n-novnc "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-novncproxy --config-file $NOVA_CONF --web $NOVNC_DIR" |
Monty Taylor | 0edfd6f | 2012-11-23 15:00:38 -0800 | [diff] [blame] | 722 | screen_it n-xvnc "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-xvpvncproxy --config-file $NOVA_CONF" |
Daniel P. Berrange | d10e12f | 2013-01-03 11:51:42 +0000 | [diff] [blame] | 723 | screen_it n-spice "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-spicehtml5proxy --config-file $NOVA_CONF --web $SPICE_DIR" |
Monty Taylor | 0edfd6f | 2012-11-23 15:00:38 -0800 | [diff] [blame] | 724 | screen_it n-cauth "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-consoleauth" |
Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 725 | |
| 726 | # Starting the nova-objectstore only if swift3 service is not enabled. |
| 727 | # Swift will act as s3 objectstore. |
| 728 | is_service_enabled swift3 || \ |
| 729 | screen_it n-obj "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-objectstore" |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | # stop_nova() - Stop running processes (non-screen) |
| 733 | function stop_nova() { |
| 734 | # Kill the nova screen windows |
Kieran Spear | fb2a3ae | 2013-03-11 23:55:49 +0000 | [diff] [blame] | 735 | # Some services are listed here twice since more than one instance |
| 736 | # of a service may be running in certain configs. |
| 737 | for serv in n-api n-cpu n-crt n-net n-sch n-novnc n-xvnc n-cauth n-spice n-cond n-cond n-cell n-cell n-api-meta; do |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 738 | screen -S $SCREEN_NAME -p $serv -X kill |
| 739 | done |
| 740 | } |
| 741 | |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 742 | |
Dean Troyer | bf67c19 | 2012-09-21 15:09:37 -0500 | [diff] [blame] | 743 | # Restore xtrace |
| 744 | $XTRACE |
Sean Dague | 584d90e | 2013-03-29 14:34:53 -0400 | [diff] [blame] | 745 | |
| 746 | # Local variables: |
| 747 | # mode: shell-script |
| 748 | # End: |