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:
34
server/routers/regions.py
Normal file
34
server/routers/regions.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""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)
|
||||
Reference in New Issue
Block a user