#!/bin/bash

if [ "$#" -ne 4 ]; then
    echo "Usage: $0 <IP> <VG> <OLD> <NEW>"
    exit 1
fi

IP="$1"
VG="$2"
OLD="$3"
NEW="$4"

TOKEN=$(< /tmp/api_token)

if [ $TOKEN == '' ]; then
    echo "Please get api token"
    echo 1
fi

echo "Rename LV:"

curl -X PUT \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d "{ \"entity\": { \"memberOf\":\"$VG\", \"newName\":\"$NEW\"}}" \
    http://$IP/api/lvm/lvs/$OLD/rename

echo "DONE"
