models.py•3.21 kB
"""
Configuration models and schemas for the Sectional MCP Panel.
"""
from pydantic import BaseModel, Field
from typing import Dict, List, Optional, Union, Any
# Resource Limits
class ResourceLimits(BaseModel):
cpuRequest: Optional[float] = None
cpuLimit: Optional[float] = None
memoryRequestMB: Optional[int] = None
memoryLimitMB: Optional[int] = None
# Runtime Options
class RuntimeOptions(BaseModel):
restartPolicy: str = "on_failure"
maxRestarts: int = 3
terminationGracePeriodSeconds: int = 30
# Security Context
class SecurityContext(BaseModel):
runAsUser: Optional[int] = None
runAsGroup: Optional[int] = None
readOnlyRootFilesystem: bool = False
# Port Configuration
class PortConfig(BaseModel):
containerPort: int
protocol: str = "TCP"
# Settings
class Settings(BaseModel):
environmentVars: Dict[str, str] = Field(default_factory=dict)
resourceLimits: ResourceLimits = Field(default_factory=ResourceLimits)
runtimeOptions: RuntimeOptions = Field(default_factory=RuntimeOptions)
securityContext: SecurityContext = Field(default_factory=SecurityContext)
# Runtime Definition
class RuntimeDefinition(BaseModel):
type: str
command: Optional[str] = None
args: List[str] = Field(default_factory=list)
workingDirectory: Optional[str] = None
ports: List[PortConfig] = Field(default_factory=list)
# Server Definition
class ServerDefinition(BaseModel):
serverName: str
description: Optional[str] = None
runtimeDefinition: RuntimeDefinition
settings: Optional[Settings] = None
# Section Definition
class SectionDefinition(BaseModel):
sectionName: str
description: Optional[str] = None
settings: Optional[Settings] = None
servers: List[ServerDefinition] = Field(default_factory=list)
# Global Defaults
class GlobalDefaults(BaseModel):
settings: Settings = Field(default_factory=Settings)
# Full Configuration
class PanelConfiguration(BaseModel):
configSchemaVersion: str
panelName: str
globalDefaults: GlobalDefaults = Field(default_factory=GlobalDefaults)
sections: List[SectionDefinition] = Field(default_factory=list)
# API Models
class SectionCreate(BaseModel):
name: str
description: Optional[str] = None
settings: Optional[Dict[str, Any]] = None
class SectionUpdate(BaseModel):
name: Optional[str] = None
description: Optional[str] = None
settings: Optional[Dict[str, Any]] = None
class ServerCreate(BaseModel):
name: str
section_id: int
description: Optional[str] = None
runtime_definition: Dict[str, Any]
settings: Optional[Dict[str, Any]] = None
class ServerUpdate(BaseModel):
name: Optional[str] = None
section_id: Optional[int] = None
description: Optional[str] = None
runtime_definition: Optional[Dict[str, Any]] = None
settings: Optional[Dict[str, Any]] = None
class ServerAction(BaseModel):
action: str # "start", "stop", "restart"
timeout: Optional[int] = None
force: Optional[bool] = False
class SectionAction(BaseModel):
action: str # "start", "stop", "restart"
concurrency: Optional[int] = 5
timeout: Optional[int] = None
force: Optional[bool] = False