- 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>
62 lines
1.9 KiB
Python
62 lines
1.9 KiB
Python
"""Startup Scripts router"""
|
|
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 CreateScriptRequest(BaseModel):
|
|
name: str
|
|
script: str
|
|
type: Optional[str] = "boot" # boot or pxe
|
|
|
|
|
|
class UpdateScriptRequest(BaseModel):
|
|
name: Optional[str] = None
|
|
script: Optional[str] = None
|
|
type: Optional[str] = None
|
|
|
|
|
|
@router.get("")
|
|
async def list_startup_scripts(
|
|
per_page: int = Query(25, le=500),
|
|
cursor: Optional[str] = None,
|
|
client: VultrClient = Depends(get_client)
|
|
):
|
|
"""List all startup scripts"""
|
|
return client.startup_scripts.list(per_page=per_page, cursor=cursor)
|
|
|
|
|
|
@router.get("/all")
|
|
async def list_all_startup_scripts(client: VultrClient = Depends(get_client)):
|
|
"""List all startup scripts (auto-paginated)"""
|
|
return {"startup_scripts": client.startup_scripts.list_all()}
|
|
|
|
|
|
@router.get("/{script_id}")
|
|
async def get_startup_script(script_id: str, client: VultrClient = Depends(get_client)):
|
|
"""Get startup script details"""
|
|
return client.startup_scripts.get(script_id)
|
|
|
|
|
|
@router.post("")
|
|
async def create_startup_script(req: CreateScriptRequest, client: VultrClient = Depends(get_client)):
|
|
"""Create a startup script"""
|
|
return client.startup_scripts.create(name=req.name, script=req.script, type=req.type)
|
|
|
|
|
|
@router.patch("/{script_id}")
|
|
async def update_startup_script(script_id: str, req: UpdateScriptRequest, client: VultrClient = Depends(get_client)):
|
|
"""Update a startup script"""
|
|
return client.startup_scripts.update(script_id, **req.model_dump(exclude_none=True))
|
|
|
|
|
|
@router.delete("/{script_id}")
|
|
async def delete_startup_script(script_id: str, client: VultrClient = Depends(get_client)):
|
|
"""Delete a startup script"""
|
|
return client.startup_scripts.delete(script_id)
|