#!/bin/bash

#rbt

DST_HOST=$1
DST_PATH=$3
VMID=$3
DSID=$4
TEMPLATE_64=$5

if [ -z "${ONE_LOCATION}" ]; then
    TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
else
    TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
fi

. $TMCOMMON

CLEAN_CMD=$(cat <<EOF
    set -e -o pipefail
    while read disk; do
        volume=(\$disk)
        if echo "\$volume" | grep "lv-one-vm" &>/dev/null; then
            $SUDO $LVREMOVE --yes \$volume
        else
            rm -rf \$disk
        fi
    done < $DST_PATH/before_ds

    rm -f $DST_PATH/before_ds
EOF
)

ssh_exec_and_log "$DST_HOST" "$CLEAN_CMD" "Error clean old logic volumes"  
exit 0

