PillarTool/pillar_tool/schemas.py

46 lines
1.0 KiB
Python

from pydantic import BaseModel
from starlette.responses import JSONResponse
# Error returns
class ErrorDetails(BaseModel):
status: str
message: str
class ErrorReturn(BaseModel):
status_code: int
content: ErrorDetails
def response(self):
return JSONResponse(self.model_dump())
class HealthCheckError(ErrorReturn):
def __init__(self, code: int, reason: str):
super().__init__(**{
'status_code': code,
'content': ErrorDetails(
status="error",
message=f"Host is not healthy: {reason}"
)
})
class HealthCheckSuccess(ErrorReturn):
def __init__(self):
super().__init__(**{
'status_code': 200,
'content': ErrorDetails(
status='ok',
message='API is healthy'
)
})
# Host operations
class HostCreateParams(BaseModel):
parent: str | None
# Hostgroup operations
class HostgroupCreateParams(BaseModel):
parent: str | None