#! /bin/bash
# vim: shiftwidth=4 tabstop=4 expandtab

function _reboot() {
    local vm=$1
    local hyp=$2

    stop_and_wait_stopped "$vm" "$hyp"

    echo -n "Wait a little bit more before restart the virtual machine..."
    run_external sleep 2
    echo " continue."

    echo "Restart virtual machine..."
    run_external ssh "$hyp" "$REAL_VIRSH" start "$vm"
    local result=$?
    [[ $result -ne 0 ]] && clean_cache
    return $result
}

_simple_command \
    --check-state running \
    --confirm "Reboot" \
    --function _reboot \
    --long-help \
        "Reboot a VM specified by name" \
        "" \
        "Note: This command trigger a shutdown order of the VM, wait its effective before" \
        "restarting the VM."
