- Change auth from X-API-Key header to Authorization: Bearer format - Add /v2 prefix to all endpoints to match Vultr API URL structure - Fix router paths (dns, firewall) to avoid duplicate path segments - Split VPC 2.0 into separate router at /v2/vpc2 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
61 lines
1.6 KiB
Python
61 lines
1.6 KiB
Python
"""VPC router (VPC 1.0)"""
|
|
from fastapi import APIRouter, Depends, Query
|
|
from typing import Optional
|
|
from pydantic import BaseModel
|
|
|
|
from vultr_api import VultrClient
|
|
from deps import get_client
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
class CreateVPCRequest(BaseModel):
|
|
region: str
|
|
description: Optional[str] = None
|
|
v4_subnet: Optional[str] = None
|
|
v4_subnet_mask: Optional[int] = None
|
|
|
|
|
|
class UpdateVPCRequest(BaseModel):
|
|
description: str
|
|
|
|
|
|
@router.get("")
|
|
async def list_vpcs(
|
|
per_page: int = Query(25, le=500),
|
|
cursor: Optional[str] = None,
|
|
client: VultrClient = Depends(get_client)
|
|
):
|
|
"""List all VPCs"""
|
|
return client.vpc.list(per_page=per_page, cursor=cursor)
|
|
|
|
|
|
@router.get("/all")
|
|
async def list_all_vpcs(client: VultrClient = Depends(get_client)):
|
|
"""List all VPCs (auto-paginated)"""
|
|
return {"vpcs": client.vpc.list_all()}
|
|
|
|
|
|
@router.get("/{vpc_id}")
|
|
async def get_vpc(vpc_id: str, client: VultrClient = Depends(get_client)):
|
|
"""Get VPC details"""
|
|
return client.vpc.get(vpc_id)
|
|
|
|
|
|
@router.post("")
|
|
async def create_vpc(req: CreateVPCRequest, client: VultrClient = Depends(get_client)):
|
|
"""Create a VPC"""
|
|
return client.vpc.create(**req.model_dump(exclude_none=True))
|
|
|
|
|
|
@router.patch("/{vpc_id}")
|
|
async def update_vpc(vpc_id: str, req: UpdateVPCRequest, client: VultrClient = Depends(get_client)):
|
|
"""Update a VPC"""
|
|
return client.vpc.update(vpc_id, description=req.description)
|
|
|
|
|
|
@router.delete("/{vpc_id}")
|
|
async def delete_vpc(vpc_id: str, client: VultrClient = Depends(get_client)):
|
|
"""Delete a VPC"""
|
|
return client.vpc.delete(vpc_id)
|