65 lines
1.7 KiB
Bash
65 lines
1.7 KiB
Bash
#!/bin/bash
|
|
|
|
# Read me: prima di esecuzione fare chmod +x export_pool.sh
|
|
# Per l'utilizzo: ./export_pool.sh pool_name
|
|
|
|
if [ $# -ne 1 ]; then
|
|
echo "Usage: $0 <pool_name>"
|
|
exit 1
|
|
fi
|
|
|
|
pool_name=$1
|
|
|
|
# Function to check if a pool is imported and available
|
|
check_pool_imported() {
|
|
local name=$1
|
|
response=$(midclt call pool.query)
|
|
echo "$response" | grep -q "\"name\": \"${name}\""
|
|
}
|
|
|
|
# Function to get the pool ID by name
|
|
get_pool_id() {
|
|
local name=$1
|
|
midclt call pool.query '[["name", "=", "'"${name}"'"]]' | jq -r '.[0].id'
|
|
}
|
|
|
|
# Check if the pool is imported and available
|
|
if ! check_pool_imported "$pool_name"; then
|
|
echo "Pool '${pool_name}' is not imported and available."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Starting export of pool '${pool_name}'..."
|
|
|
|
# Get pool ID for export
|
|
pool_id=$(get_pool_id "$pool_name")
|
|
|
|
# Start the pool export job
|
|
export_job_id=$(midclt call pool.export "$pool_id")
|
|
echo "Started pool export job with ID: $export_job_id"
|
|
|
|
# Poll until the export job is complete
|
|
while true; do
|
|
echo "Checking export job status..."
|
|
export_job_status=$(midclt call core.get_jobs "[[\"id\", \"=\", ${export_job_id}]]" | jq -r '.[0]')
|
|
export_state=$(echo $export_job_status | jq -r '.state')
|
|
echo "Export job state: $export_state"
|
|
|
|
if [ "$export_state" == "SUCCESS" ]; then
|
|
echo "Export job succeeded."
|
|
break
|
|
elif [ "$export_state" == "FAILED" ]; then
|
|
echo "Export job failed"
|
|
exit 1
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
# After export, double-check if the pool is no longer available
|
|
if check_pool_imported "$pool_name"; then
|
|
echo "Pool '${pool_name}' still found after export attempt. Error!"
|
|
exit 1
|
|
else
|
|
echo "Pool '${pool_name}' successfully exported and no longer available."
|
|
exit 0
|
|
fi |