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."}