#!/bin/bash

LIB_DIR="$( realpath "$( dirname "$( realpath "$0" )" )/../../lib/eehyp-tools" )"
if [[ -e "$LIB_DIR/common" ]]; then
    # shellcheck source=/dev/null
    source "$LIB_DIR/common"
else
    echo "Failed to load eehyp-tools common lib"
    exit 1
fi

# Detect virsh command
cmd=""
vm=""
for arg in "$@"; do
	case "$arg" in
		-*) ;;
		*)
			if [[ "${cmd:-null}" == "null" ]]; then
				cmd="$arg"
			elif [[ "${vm:-null}" == "null" ]]; then
				vm="$arg"
				break
			fi
			;;
	esac
done

# Banned blockresize command
if [[ "$cmd" == "blockresize" ]]; then
	[[ "${vm:-null}" == "null" ]] && vm="eeid-domain"
	cat << EOF
/!\\ BANNED COMMAND - #118041 /!\\

Please use 'vm volume resize [VM] [volume RBD path] [+|-][size in GiB]' instead

See 'vm volume resize -h' for details.

Example: vm volume resize '$vm' 'libvirt-pool/$vm' +10

Note: use 'vm volume ls $vm' to list volume of VM $vm with their current size.

EOF
	exit 1
fi

exec "$REAL_VIRSH" "$@"
