#!/bin/bash
# Create OSDs on R630-01 250GB drives
set -e

DRIVES=("sdc" "sdd" "sde" "sdf" "sdg" "sdh")

echo "=== Creating OSDs on R630-01 ==="

for disk in "${DRIVES[@]}"; do
    if [ ! -e "/dev/$disk" ]; then
        echo "Skipping /dev/$disk (not found)"
        continue
    fi
    
    echo "Creating OSD on /dev/$disk..."
    
    # Check if already an OSD
    if ceph-volume lvm list /dev/$disk 2>/dev/null | grep -q "osd\."; then
        echo "  /dev/$disk already has an OSD, skipping"
        continue
    fi
    
    # Create OSD
    ceph-volume lvm create --data /dev/$disk
    
    # Get OSD ID and start service
    OSD_ID=$(ceph-volume lvm list /dev/$disk 2>/dev/null | grep -oP "osd\.\K\d+" | head -1)
    if [ -n "$OSD_ID" ]; then
        systemctl enable ceph-osd@$OSD_ID
        systemctl start ceph-osd@$OSD_ID
        echo "  OSD $OSD_ID created and started"
    fi
    
    sleep 2
done

echo ""
echo "=== OSD Creation Complete ==="
echo "Run 'ceph osd tree' to verify OSDs"

