import React, { useState, useEffect, useCallback } from 'react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/index'; import { Button } from '@/components/ui/index'; import { RefreshCw } from 'lucide-react'; import { PoolList, OSDList, CephHealthWidget, MonitorList } from '@/components/Proxmox'; import { listProxmoxClusters, listCephPools, listCephOsd, getCephHealth } from '@/lib/proxmoxClient'; import { toast } from 'sonner'; export function ProxmoxCephPage() { const [clusterId, setClusterId] = useState(''); // eslint-disable-next-line @typescript-eslint/no-explicit-any const [health, setHealth] = useState(null); // eslint-disable-next-line @typescript-eslint/no-explicit-any const [pools, setPools] = useState([]); // eslint-disable-next-line @typescript-eslint/no-explicit-any const [osds, setOsds] = useState([]); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [isCephEnabled, setIsCephEnabled] = useState(null); const loadData = useCallback(async (cId: string) => { if (!cId) return; setLoading(true); setError(null); // Check Ceph availability by fetching health first let cephAvailable = false; try { const h = await getCephHealth(cId); setHealth(h); cephAvailable = true; } catch { setIsCephEnabled(false); setLoading(false); return; } if (cephAvailable) { setIsCephEnabled(true); const [poolsResult, osdsResult] = await Promise.allSettled([ listCephPools(cId), listCephOsd(cId), ]); if (poolsResult.status === 'fulfilled') { setPools(poolsResult.value); } else { toast.error('Failed to load Ceph pools'); } if (osdsResult.status === 'fulfilled') { setOsds(osdsResult.value); } else { toast.error('Failed to load Ceph OSDs'); } } setLoading(false); }, []); useEffect(() => { listProxmoxClusters() .then((cls) => { if (cls.length > 0) { setClusterId(cls[0].id); loadData(cls[0].id); } else { setIsCephEnabled(false); } }) .catch((err) => { console.error('Failed to load clusters:', err); setError('Failed to load clusters'); setIsCephEnabled(false); }); }, [loadData]); const handleRefresh = () => { if (clusterId) loadData(clusterId); }; if (isCephEnabled === false) { return (

Ceph Storage

Manage Ceph clusters and storage

{error ? (

{error}

) : ( <>

Ceph is not configured on this cluster

Ceph storage requires a dedicated Ceph cluster deployment on the Proxmox nodes.

)}
); } return (

Ceph Storage

Manage Ceph clusters and storage

Ceph Health {health ? ( ) : (

Loading health data...

)}
Pools OSDs
Monitors
); }