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:
75
vultr_api/resources/plans.py
Normal file
75
vultr_api/resources/plans.py
Normal file
@@ -0,0 +1,75 @@
|
||||
"""
|
||||
Plans Resource
|
||||
|
||||
Available plan listings
|
||||
"""
|
||||
|
||||
from typing import Dict, List
|
||||
from .base import BaseResource
|
||||
|
||||
|
||||
class PlansResource(BaseResource):
|
||||
"""
|
||||
Plan listings
|
||||
|
||||
Usage:
|
||||
# List cloud compute plans
|
||||
plans = client.plans.list()
|
||||
|
||||
# List bare metal plans
|
||||
bm_plans = client.plans.list_bare_metal()
|
||||
"""
|
||||
|
||||
def list(
|
||||
self,
|
||||
plan_type: str = None,
|
||||
per_page: int = 100,
|
||||
cursor: str = None,
|
||||
os: str = None
|
||||
) -> Dict:
|
||||
"""
|
||||
List cloud compute plans
|
||||
|
||||
Args:
|
||||
plan_type: Filter by type ("all", "vc2", "vhf", "vdc", "voc", "voc-g", "voc-c", "voc-m", "voc-s", "vcg")
|
||||
per_page: Items per page
|
||||
cursor: Pagination cursor
|
||||
os: Filter by supported OS ("windows")
|
||||
|
||||
Returns:
|
||||
Dict with 'plans' list and 'meta' pagination
|
||||
"""
|
||||
params = {"per_page": per_page}
|
||||
if plan_type:
|
||||
params["type"] = plan_type
|
||||
if cursor:
|
||||
params["cursor"] = cursor
|
||||
if os:
|
||||
params["os"] = os
|
||||
|
||||
return self.client.get("plans", params=params)
|
||||
|
||||
def list_all(self, plan_type: str = None, os: str = None) -> List[Dict]:
|
||||
"""List all plans (auto-paginate)"""
|
||||
params = {}
|
||||
if plan_type:
|
||||
params["type"] = plan_type
|
||||
if os:
|
||||
params["os"] = os
|
||||
return self.client.paginate("plans", "plans", params=params)
|
||||
|
||||
def list_bare_metal(self, per_page: int = 100, cursor: str = None) -> Dict:
|
||||
"""
|
||||
List bare metal plans
|
||||
|
||||
Returns:
|
||||
Dict with 'plans' list and 'meta' pagination
|
||||
"""
|
||||
params = {"per_page": per_page}
|
||||
if cursor:
|
||||
params["cursor"] = cursor
|
||||
return self.client.get("plans-metal", params=params)
|
||||
|
||||
def list_all_bare_metal(self) -> List[Dict]:
|
||||
"""List all bare metal plans (auto-paginate)"""
|
||||
return self.client.paginate("plans-metal", "plans")
|
||||
Reference in New Issue
Block a user