34 lines
815 B
Python
34 lines
815 B
Python
from fastapi import APIRouter
|
|
from pydantic import BaseModel
|
|
from database import insert_metal_node, fetch_all
|
|
|
|
router = APIRouter()
|
|
|
|
class MetalNode(BaseModel):
|
|
name: str
|
|
location: str
|
|
vendor: str
|
|
cpu: int
|
|
memory: str
|
|
storage: str
|
|
time_on_duty: int
|
|
initial_cost: float
|
|
|
|
@router.get("/metal/data")
|
|
def get_metal_data():
|
|
return {"metal_nodes": fetch_all("metal_nodes")}
|
|
|
|
@router.post("/metal/data")
|
|
def add_metal_data(node: MetalNode):
|
|
insert_metal_node(
|
|
name=node.name,
|
|
location=node.location,
|
|
vendor=node.vendor,
|
|
cpu=node.cpu,
|
|
memory=node.memory,
|
|
storage=node.storage,
|
|
time_on_duty=node.time_on_duty,
|
|
initial_cost=node.initial_cost
|
|
)
|
|
return {"message": f"Metal node '{node.name}' added successfully."}
|