#!/bin/bash
set -eux

# Used by all compute
install-packages bridge-utils ebtables qemu-utils syslinux

# LIBVIRT_DEFAULT_URI needs to be set due to
# https://bugs.launchpad.net/tripleo/+bug/1226310
CONFIG_PARAMETERS="--config-dir /etc/nova"
TEMPLATE_ROOT=$(dirname $0)/../os-apply-config

if [ -d ${TEMPLATE_ROOT}/etc/nova/compute ]; then
    CONFIG_PARAMETERS="${CONFIG_PARAMETERS} --config-dir /etc/nova/compute"
fi

os-svc-daemon -i "$NOVA_VENV_DIR" -e "LIBVIRT_DEFAULT_URI=qemu:///system" nova-compute  nova nova-compute "${CONFIG_PARAMETERS}"


# Use the rootwrap config from the source repo.
install -o root -g root -m 0755 -d /etc/nova/rootwrap.d
for f in $(ls /opt/stack/nova/etc/nova/rootwrap.d/); do
    install -o root -g root -m 644 /opt/stack/nova/etc/nova/rootwrap.d/$f /etc/nova/rootwrap.d/$f
done
install -o root -g root -m 0644 /opt/stack/nova/etc/nova/rootwrap.conf /etc/nova/rootwrap.conf
