Initial commit: FastAPI JBOD monitor backend
This commit is contained in:
20
routers/drives.py
Normal file
20
routers/drives.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
from models.schemas import DriveDetail
|
||||
from services.smart import get_smart_data
|
||||
|
||||
router = APIRouter(prefix="/api/drives", tags=["drives"])
|
||||
|
||||
|
||||
@router.get("/{device}", response_model=DriveDetail)
|
||||
async def get_drive_detail(device: str):
|
||||
"""Get SMART detail for a specific block device."""
|
||||
try:
|
||||
data = await get_smart_data(device)
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
if "error" in data:
|
||||
raise HTTPException(status_code=502, detail=data["error"])
|
||||
|
||||
return DriveDetail(**data)
|
||||
Reference in New Issue
Block a user