Files
metalcheck/app/routes/vm.py
Aleksandr Tcitlionok 209bf98fb4 init(app): initial version
2024-12-04 08:30:25 +00:00

30 lines
693 B
Python

from fastapi import APIRouter
from pydantic import BaseModel
from database import insert_virtual_machine, fetch_all
router = APIRouter()
class VirtualMachine(BaseModel):
name: str
location: str
cpu: int
memory: str
storage: str
type: str
@router.get("/vm/data")
def get_vm_data():
return {"virtual_machines": fetch_all("virtual_machines")}
@router.post("/vm/data")
def add_vm_data(vm: VirtualMachine):
insert_virtual_machine(
name=vm.name,
location=vm.location,
cpu=vm.cpu,
memory=vm.memory,
storage=vm.storage,
vm_type=vm.type
)
return {"message": f"Virtual machine '{vm.name}' added successfully."}