- 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>
113 lines
2.7 KiB
Python
113 lines
2.7 KiB
Python
"""
|
|
Startup Scripts Resource
|
|
|
|
Startup script management
|
|
"""
|
|
|
|
from typing import Dict, List
|
|
from .base import BaseResource
|
|
|
|
|
|
class StartupScriptsResource(BaseResource):
|
|
"""
|
|
Startup script management
|
|
|
|
Usage:
|
|
# List scripts
|
|
scripts = client.startup_scripts.list()
|
|
|
|
# Create script
|
|
script = client.startup_scripts.create(
|
|
name="my-script",
|
|
script="#!/bin/bash\\necho 'Hello'",
|
|
script_type="boot"
|
|
)
|
|
|
|
# Delete script
|
|
client.startup_scripts.delete("script-id")
|
|
"""
|
|
|
|
def list(self, per_page: int = 100, cursor: str = None) -> Dict:
|
|
"""
|
|
List startup scripts
|
|
|
|
Returns:
|
|
Dict with 'startup_scripts' list and 'meta' pagination
|
|
"""
|
|
params = {"per_page": per_page}
|
|
if cursor:
|
|
params["cursor"] = cursor
|
|
return self.client.get("startup-scripts", params=params)
|
|
|
|
def list_all(self) -> List[Dict]:
|
|
"""List all startup scripts (auto-paginate)"""
|
|
return self.client.paginate("startup-scripts", "startup_scripts")
|
|
|
|
def get(self, startup_script_id: str) -> Dict:
|
|
"""
|
|
Get startup script details
|
|
|
|
Args:
|
|
startup_script_id: Script ID
|
|
|
|
Returns:
|
|
Script details
|
|
"""
|
|
response = self.client.get(f"startup-scripts/{startup_script_id}")
|
|
return response.get("startup_script", {})
|
|
|
|
def create(
|
|
self,
|
|
name: str,
|
|
script: str,
|
|
script_type: str = "boot"
|
|
) -> Dict:
|
|
"""
|
|
Create a startup script
|
|
|
|
Args:
|
|
name: Script name
|
|
script: Script content (base64 or plain text)
|
|
script_type: Type ("boot" or "pxe")
|
|
|
|
Returns:
|
|
Created script details
|
|
"""
|
|
response = self.client.post("startup-scripts", {
|
|
"name": name,
|
|
"script": script,
|
|
"type": script_type
|
|
})
|
|
return response.get("startup_script", {})
|
|
|
|
def update(
|
|
self,
|
|
startup_script_id: str,
|
|
name: str = None,
|
|
script: str = None
|
|
) -> None:
|
|
"""
|
|
Update a startup script
|
|
|
|
Args:
|
|
startup_script_id: Script ID
|
|
name: New name
|
|
script: New script content
|
|
"""
|
|
data = {}
|
|
if name:
|
|
data["name"] = name
|
|
if script:
|
|
data["script"] = script
|
|
|
|
self.client.patch(f"startup-scripts/{startup_script_id}", data)
|
|
|
|
def delete(self, startup_script_id: str) -> None:
|
|
"""
|
|
Delete a startup script
|
|
|
|
Args:
|
|
startup_script_id: Script ID to delete
|
|
"""
|
|
self.client.delete(f"startup-scripts/{startup_script_id}")
|