#!/bin/bash
# check if nova is configured to resume guests power state at hypervisor startup
LIBVIRTCONF=/etc/sysconfig/libvirt-guests
NOVACONF=/etc/nova/nova.conf
NOVASETTING="^resume_guests_state_on_host_boot"
LIBVIRTBOOT=$(grep ^ON_BOOT $LIBVIRTCONF | awk -F "=" '{print $2}' | sed 's/ //')
LIBVIRTOFF=$(grep ^ON_SHUTDOWN $LIBVIRTCONF | awk -F "=" '{print $2}' | sed 's/ //')
NOVASTRING=$(awk '/\[DEFAULT\]/,/\[api_database\]/' $NOVACONF | grep $NOVASETTING | awk -F "=" '{print $2}' | sed 's/ //')
ON_BOOT=$LIBVIRTBOOT
ON_SHUTDOWN=$LIBVIRTOFF
resume_guests_state_on_host_boot=$NOVASTRING
if [[ "$LIBVIRTBOOT" == "ignore" && "$LIBVIRTOFF" == "shutdown" && "$NOVASTRING" == "true" ]]; then
echo "$(tput setaf 2)>>>$(tput sgr0) compute node is configured to restore guests state at startup $(tput setaf 2)<<<$(tput sgr0)"
exit 0
else
echo "$(tput setaf 1)>>>$(tput sgr0) compute node is NOT configured to restore guests state at startup $(tput setaf 1)<<<$(tput sgr0)"
exit 1
fi