Make API endpoints compatible with Vultr API v2 format
- 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>
This commit is contained in:
83
server/routers/vpc2.py
Normal file
83
server/routers/vpc2.py
Normal file
@@ -0,0 +1,83 @@
|
||||
"""VPC 2.0 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 CreateVPC2Request(BaseModel):
|
||||
region: str
|
||||
description: Optional[str] = None
|
||||
ip_block: Optional[str] = None
|
||||
prefix_length: Optional[int] = None
|
||||
|
||||
|
||||
class AttachVPC2Request(BaseModel):
|
||||
nodes: List[dict] # [{"id": "instance_id", "ip_address": "10.0.0.1"}, ...]
|
||||
|
||||
|
||||
@router.get("")
|
||||
async def list_vpc2s(
|
||||
per_page: int = Query(25, le=500),
|
||||
cursor: Optional[str] = None,
|
||||
client: VultrClient = Depends(get_client)
|
||||
):
|
||||
"""List all VPC 2.0 networks"""
|
||||
return client.vpc.list_vpc2(per_page=per_page, cursor=cursor)
|
||||
|
||||
|
||||
@router.get("/all")
|
||||
async def list_all_vpc2s(client: VultrClient = Depends(get_client)):
|
||||
"""List all VPC 2.0 networks (auto-paginated)"""
|
||||
return {"vpcs": client.vpc.list_all_vpc2()}
|
||||
|
||||
|
||||
@router.get("/{vpc_id}")
|
||||
async def get_vpc2(vpc_id: str, client: VultrClient = Depends(get_client)):
|
||||
"""Get VPC 2.0 details"""
|
||||
return client.vpc.get_vpc2(vpc_id)
|
||||
|
||||
|
||||
@router.post("")
|
||||
async def create_vpc2(req: CreateVPC2Request, client: VultrClient = Depends(get_client)):
|
||||
"""Create a VPC 2.0 network"""
|
||||
return client.vpc.create_vpc2(**req.model_dump(exclude_none=True))
|
||||
|
||||
|
||||
@router.patch("/{vpc_id}")
|
||||
async def update_vpc2(vpc_id: str, description: str, client: VultrClient = Depends(get_client)):
|
||||
"""Update a VPC 2.0 network"""
|
||||
return client.vpc.update_vpc2(vpc_id, description=description)
|
||||
|
||||
|
||||
@router.delete("/{vpc_id}")
|
||||
async def delete_vpc2(vpc_id: str, client: VultrClient = Depends(get_client)):
|
||||
"""Delete a VPC 2.0 network"""
|
||||
return client.vpc.delete_vpc2(vpc_id)
|
||||
|
||||
|
||||
@router.get("/{vpc_id}/nodes")
|
||||
async def list_vpc2_nodes(
|
||||
vpc_id: str,
|
||||
per_page: int = Query(25, le=500),
|
||||
cursor: Optional[str] = None,
|
||||
client: VultrClient = Depends(get_client)
|
||||
):
|
||||
"""List nodes attached to a VPC 2.0"""
|
||||
return client.vpc.list_vpc2_nodes(vpc_id, per_page=per_page, cursor=cursor)
|
||||
|
||||
|
||||
@router.post("/{vpc_id}/nodes/attach")
|
||||
async def attach_vpc2_nodes(vpc_id: str, req: AttachVPC2Request, client: VultrClient = Depends(get_client)):
|
||||
"""Attach nodes to a VPC 2.0"""
|
||||
return client.vpc.attach_vpc2_nodes(vpc_id, nodes=req.nodes)
|
||||
|
||||
|
||||
@router.post("/{vpc_id}/nodes/detach")
|
||||
async def detach_vpc2_nodes(vpc_id: str, req: AttachVPC2Request, client: VultrClient = Depends(get_client)):
|
||||
"""Detach nodes from a VPC 2.0"""
|
||||
return client.vpc.detach_vpc2_nodes(vpc_id, nodes=req.nodes)
|
||||
Reference in New Issue
Block a user