init(app): initial version
This commit is contained in:
29
app/routes/vm.py
Normal file
29
app/routes/vm.py
Normal file
@@ -0,0 +1,29 @@
|
||||
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."}
|
||||
Reference in New Issue
Block a user