Initial commit: Vultr API v2 Python wrapper with FastAPI server

- vultr_api/: Python library wrapping Vultr API v2
  - 17 resource modules (instances, dns, firewall, vpc, etc.)
  - Pagination support, error handling

- server/: FastAPI REST server
  - All API endpoints exposed via HTTP
  - X-API-Key header authentication
  - Swagger docs at /docs

- Podman quadlet config for systemd deployment

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
HWANG BYUNGHA
2026-01-22 01:08:17 +09:00
commit 184054c6c1
48 changed files with 6058 additions and 0 deletions

View File

@@ -0,0 +1,118 @@
"""Bare Metal router"""
from fastapi import APIRouter, Depends, Query
from typing import Optional, List
from pydantic import BaseModel
from vultr_api import VultrClient
from deps import get_client
router = APIRouter()
class CreateBareMetalRequest(BaseModel):
region: str
plan: str
os_id: Optional[int] = None
snapshot_id: Optional[str] = None
app_id: Optional[int] = None
image_id: Optional[str] = None
script_id: Optional[str] = None
ssh_key_ids: Optional[List[str]] = None
enable_ipv6: Optional[bool] = None
hostname: Optional[str] = None
label: Optional[str] = None
tags: Optional[List[str]] = None
class UpdateBareMetalRequest(BaseModel):
label: Optional[str] = None
tags: Optional[List[str]] = None
enable_ipv6: Optional[bool] = None
@router.get("")
async def list_bare_metal(
per_page: int = Query(25, le=500),
cursor: Optional[str] = None,
client: VultrClient = Depends(get_client)
):
"""List all bare metal servers"""
return client.bare_metal.list(per_page=per_page, cursor=cursor)
@router.get("/all")
async def list_all_bare_metal(client: VultrClient = Depends(get_client)):
"""List all bare metal servers (auto-paginated)"""
return {"bare_metals": client.bare_metal.list_all()}
@router.get("/{baremetal_id}")
async def get_bare_metal(baremetal_id: str, client: VultrClient = Depends(get_client)):
"""Get bare metal server details"""
return client.bare_metal.get(baremetal_id)
@router.post("")
async def create_bare_metal(req: CreateBareMetalRequest, client: VultrClient = Depends(get_client)):
"""Create a bare metal server"""
return client.bare_metal.create(**req.model_dump(exclude_none=True))
@router.patch("/{baremetal_id}")
async def update_bare_metal(baremetal_id: str, req: UpdateBareMetalRequest, client: VultrClient = Depends(get_client)):
"""Update a bare metal server"""
return client.bare_metal.update(baremetal_id, **req.model_dump(exclude_none=True))
@router.delete("/{baremetal_id}")
async def delete_bare_metal(baremetal_id: str, client: VultrClient = Depends(get_client)):
"""Delete a bare metal server"""
return client.bare_metal.delete(baremetal_id)
@router.post("/{baremetal_id}/start")
async def start_bare_metal(baremetal_id: str, client: VultrClient = Depends(get_client)):
"""Start a bare metal server"""
return client.bare_metal.start(baremetal_id)
@router.post("/{baremetal_id}/halt")
async def halt_bare_metal(baremetal_id: str, client: VultrClient = Depends(get_client)):
"""Halt a bare metal server"""
return client.bare_metal.halt(baremetal_id)
@router.post("/{baremetal_id}/reboot")
async def reboot_bare_metal(baremetal_id: str, client: VultrClient = Depends(get_client)):
"""Reboot a bare metal server"""
return client.bare_metal.reboot(baremetal_id)
@router.post("/{baremetal_id}/reinstall")
async def reinstall_bare_metal(baremetal_id: str, hostname: Optional[str] = None, client: VultrClient = Depends(get_client)):
"""Reinstall a bare metal server"""
return client.bare_metal.reinstall(baremetal_id, hostname=hostname)
@router.get("/{baremetal_id}/ipv4")
async def list_ipv4(baremetal_id: str, client: VultrClient = Depends(get_client)):
"""List IPv4 addresses for a bare metal server"""
return client.bare_metal.list_ipv4(baremetal_id)
@router.get("/{baremetal_id}/ipv6")
async def list_ipv6(baremetal_id: str, client: VultrClient = Depends(get_client)):
"""List IPv6 addresses for a bare metal server"""
return client.bare_metal.list_ipv6(baremetal_id)
@router.get("/{baremetal_id}/bandwidth")
async def get_bandwidth(baremetal_id: str, client: VultrClient = Depends(get_client)):
"""Get bandwidth usage for a bare metal server"""
return client.bare_metal.bandwidth(baremetal_id)
@router.get("/{baremetal_id}/user-data")
async def get_user_data(baremetal_id: str, client: VultrClient = Depends(get_client)):
"""Get user data for a bare metal server"""
return client.bare_metal.get_user_data(baremetal_id)