Initial commit: FastAPI JBOD monitor backend
This commit is contained in:
24
routers/enclosures.py
Normal file
24
routers/enclosures.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
from models.schemas import Enclosure, SlotInfo
|
||||
from services.enclosure import discover_enclosures, list_slots
|
||||
|
||||
router = APIRouter(prefix="/api/enclosures", tags=["enclosures"])
|
||||
|
||||
|
||||
@router.get("", response_model=list[Enclosure])
|
||||
async def get_enclosures():
|
||||
"""Discover all SES enclosures."""
|
||||
return discover_enclosures()
|
||||
|
||||
|
||||
@router.get("/{enclosure_id}/drives", response_model=list[SlotInfo])
|
||||
async def get_enclosure_drives(enclosure_id: str):
|
||||
"""List all drive slots for an enclosure."""
|
||||
slots = list_slots(enclosure_id)
|
||||
if not slots:
|
||||
# Check if the enclosure exists at all
|
||||
enclosures = discover_enclosures()
|
||||
if not any(e["id"] == enclosure_id for e in enclosures):
|
||||
raise HTTPException(status_code=404, detail=f"Enclosure '{enclosure_id}' not found")
|
||||
return slots
|
||||
Reference in New Issue
Block a user