- 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>
35 lines
950 B
Python
35 lines
950 B
Python
"""Regions router"""
|
|
from fastapi import APIRouter, Depends, Query
|
|
from typing import Optional
|
|
|
|
from vultr_api import VultrClient
|
|
from deps import get_client
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("")
|
|
async def list_regions(
|
|
per_page: int = Query(25, le=500),
|
|
cursor: Optional[str] = None,
|
|
client: VultrClient = Depends(get_client)
|
|
):
|
|
"""List all regions"""
|
|
return client.regions.list(per_page=per_page, cursor=cursor)
|
|
|
|
|
|
@router.get("/all")
|
|
async def list_all_regions(client: VultrClient = Depends(get_client)):
|
|
"""List all regions (auto-paginated)"""
|
|
return {"regions": client.regions.list_all()}
|
|
|
|
|
|
@router.get("/{region_id}/availability")
|
|
async def list_region_availability(
|
|
region_id: str,
|
|
plan_type: Optional[str] = None, # vc2, vhf, vdc, etc.
|
|
client: VultrClient = Depends(get_client)
|
|
):
|
|
"""List available plans in a region"""
|
|
return client.regions.list_availability(region_id, plan_type=plan_type)
|