This commit is contained in:
2025-12-20 03:47:10 +01:00
parent 8428bf9c82
commit dcba044cd6
179 changed files with 10345 additions and 786 deletions

View File

@@ -3,7 +3,7 @@ Linux BenchTools - Devices API
"""
import json
from fastapi import APIRouter, Depends, HTTPException, status, Query
from fastapi import APIRouter, Depends, HTTPException, status, Query, Response
from sqlalchemy.orm import Session
from typing import List
@@ -68,7 +68,8 @@ async def get_devices(
disk_score=last_bench.disk_score,
network_score=last_bench.network_score,
gpu_score=last_bench.gpu_score,
bench_script_version=last_bench.bench_script_version
bench_script_version=last_bench.bench_script_version,
notes=last_bench.notes
)
items.append(DeviceSummary(
@@ -80,6 +81,9 @@ async def get_devices(
location=device.location,
owner=device.owner,
tags=device.tags,
purchase_store=device.purchase_store,
purchase_date=device.purchase_date,
purchase_price=device.purchase_price,
created_at=device.created_at.isoformat(),
updated_at=device.updated_at.isoformat(),
last_benchmark=last_bench_summary
@@ -125,7 +129,8 @@ async def get_device(
disk_score=last_bench.disk_score,
network_score=last_bench.network_score,
gpu_score=last_bench.gpu_score,
bench_script_version=last_bench.bench_script_version
bench_script_version=last_bench.bench_script_version,
notes=last_bench.notes
)
# Get last hardware snapshot
@@ -146,20 +151,40 @@ async def get_device(
cpu_base_freq_ghz=last_snapshot.cpu_base_freq_ghz,
cpu_max_freq_ghz=last_snapshot.cpu_max_freq_ghz,
ram_total_mb=last_snapshot.ram_total_mb,
ram_used_mb=last_snapshot.ram_used_mb,
ram_free_mb=last_snapshot.ram_free_mb,
ram_shared_mb=last_snapshot.ram_shared_mb,
ram_slots_total=last_snapshot.ram_slots_total,
ram_slots_used=last_snapshot.ram_slots_used,
gpu_summary=last_snapshot.gpu_summary,
gpu_model=last_snapshot.gpu_model,
storage_summary=last_snapshot.storage_summary,
storage_devices_json=last_snapshot.storage_devices_json,
partitions_json=last_snapshot.partitions_json,
network_interfaces_json=last_snapshot.network_interfaces_json,
network_shares_json=last_snapshot.network_shares_json,
os_name=last_snapshot.os_name,
os_version=last_snapshot.os_version,
kernel_version=last_snapshot.kernel_version,
architecture=last_snapshot.architecture,
virtualization_type=last_snapshot.virtualization_type,
screen_resolution=last_snapshot.screen_resolution,
display_server=last_snapshot.display_server,
session_type=last_snapshot.session_type,
last_boot_time=last_snapshot.last_boot_time,
uptime_seconds=last_snapshot.uptime_seconds,
battery_percentage=last_snapshot.battery_percentage,
battery_status=last_snapshot.battery_status,
battery_health=last_snapshot.battery_health,
hostname=last_snapshot.hostname,
desktop_environment=last_snapshot.desktop_environment,
motherboard_vendor=last_snapshot.motherboard_vendor,
motherboard_model=last_snapshot.motherboard_model
motherboard_model=last_snapshot.motherboard_model,
bios_vendor=last_snapshot.bios_vendor,
bios_version=last_snapshot.bios_version,
bios_date=last_snapshot.bios_date,
pci_devices_json=last_snapshot.pci_devices_json,
usb_devices_json=last_snapshot.usb_devices_json
)
# Get documents for this device
@@ -189,6 +214,9 @@ async def get_device(
location=device.location,
owner=device.owner,
tags=device.tags,
purchase_store=device.purchase_store,
purchase_date=device.purchase_date,
purchase_price=device.purchase_price,
created_at=device.created_at.isoformat(),
updated_at=device.updated_at.isoformat(),
last_benchmark=last_bench_summary,
@@ -232,7 +260,8 @@ async def get_device_benchmarks(
disk_score=b.disk_score,
network_score=b.network_score,
gpu_score=b.gpu_score,
bench_script_version=b.bench_script_version
bench_script_version=b.bench_script_version,
notes=b.notes
)
for b in benchmarks
]
@@ -276,3 +305,25 @@ async def update_device(
# Return updated device (reuse get_device logic)
return await get_device(device_id, db)
@router.delete("/devices/{device_id}", status_code=status.HTTP_204_NO_CONTENT)
async def delete_device(
device_id: int,
db: Session = Depends(get_db)
):
"""
Delete a device and all related data
"""
device = db.query(Device).filter(Device.id == device_id).first()
if not device:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=f"Device {device_id} not found"
)
db.delete(device)
db.commit()
return Response(status_code=status.HTTP_204_NO_CONTENT)