CI/CD Pipeline / Unit Tests (Python 3.12) (push) Successful in 30s
CI/CD Pipeline / Unit Tests (Python 3.13) (push) Successful in 35s
CI/CD Pipeline / Code Quality & Linting (push) Successful in 27s
CI/CD Pipeline / Security Scanning (push) Successful in 2m23s
CI/CD Pipeline / Unit Tests (Python 3.11) (push) Successful in 24s
CI/CD Pipeline / Integration Tests (push) Successful in 26s
CI/CD Pipeline / Generate Test Report (push) Successful in 9s
CI/CD Pipeline / Build Docker Image (push) Successful in 41s
CI/CD Pipeline / CI/CD Pipeline Status (push) Successful in 2s
112 lines
2.4 KiB
Python
112 lines
2.4 KiB
Python
"""
|
|
Data Models Module
|
|
|
|
Pydantic models for type-safe data handling throughout the application.
|
|
Provides validation and serialization for API responses and internal data.
|
|
"""
|
|
|
|
from typing import Any, Dict, List, Optional
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class ResourceAttributes(BaseModel):
|
|
"""Current resource usage attributes from panel API."""
|
|
|
|
current_state: str
|
|
resources: "ResourceUsage"
|
|
|
|
|
|
class ResourceUsage(BaseModel):
|
|
"""Individual resource metrics."""
|
|
|
|
cpu_absolute: float = 0.0
|
|
memory_bytes: int = 0
|
|
disk_bytes: int = 0
|
|
network_rx_bytes: int = 0
|
|
network_tx_bytes: int = 0
|
|
uptime: int = 0
|
|
|
|
|
|
class ServerAttributes(BaseModel):
|
|
"""Server attributes from panel API."""
|
|
|
|
identifier: str
|
|
name: str
|
|
description: Optional[str] = None
|
|
suspended: bool = False
|
|
limits: "ServerLimits" = Field(default_factory=lambda: ServerLimits())
|
|
|
|
|
|
class ServerLimits(BaseModel):
|
|
"""Server resource limits."""
|
|
|
|
cpu: int = 0
|
|
memory: int = 0
|
|
disk: int = 0
|
|
|
|
|
|
class ServerRelationships(BaseModel):
|
|
"""Server relationships data."""
|
|
|
|
allocations: Optional["AllocationsData"] = None
|
|
|
|
|
|
class AllocationsData(BaseModel):
|
|
"""Allocations data container."""
|
|
|
|
data: List["Allocation"] = Field(default_factory=list)
|
|
|
|
|
|
class Allocation(BaseModel):
|
|
"""Individual allocation (IP/port)."""
|
|
|
|
attributes: "AllocationAttributes"
|
|
|
|
|
|
class AllocationAttributes(BaseModel):
|
|
"""Allocation attributes."""
|
|
|
|
ip_alias: str = "Unknown"
|
|
port: int = 0
|
|
is_default: bool = False
|
|
|
|
|
|
class ServerData(BaseModel):
|
|
"""Complete server data from panel API."""
|
|
|
|
attributes: ServerAttributes
|
|
relationships: Optional[ServerRelationships] = None
|
|
|
|
|
|
class ServerResources(BaseModel):
|
|
"""Server resources response from panel API."""
|
|
|
|
attributes: ResourceAttributes
|
|
|
|
|
|
class APIResponse(BaseModel):
|
|
"""Generic API response wrapper."""
|
|
|
|
status: str = "success"
|
|
data: Any = None
|
|
message: Optional[str] = None
|
|
errors: Optional[List[Dict[str, Any]]] = None
|
|
|
|
|
|
class ServerListResponse(BaseModel):
|
|
"""Server list response from panel API."""
|
|
|
|
data: List[Dict[str, Any]] = Field(default_factory=list)
|
|
meta: Optional[Dict[str, Any]] = None
|
|
|
|
|
|
class EmbedLocation(BaseModel):
|
|
"""Embed location tracking data."""
|
|
|
|
channel_id: str
|
|
message_id: str
|
|
|
|
|
|
# Rebuild models to resolve forward references
|
|
ResourceAttributes.model_rebuild()
|
|
ServerAttributes.model_rebuild() |