forked from jasima/pali-lili
76 lines
2 KiB
Python
76 lines
2 KiB
Python
from datetime import datetime
|
|
from enum import Enum
|
|
from typing import Any
|
|
from uuid import UUID
|
|
|
|
from pydantic import ConfigDict
|
|
|
|
from src.schemas import CustomModel, TimestampMixin, CustomDatetime, IdMixin
|
|
from src.tofu.models import TofuInstanceStatus, TofuInstanceTaskType, TofuInstanceTaskStatus
|
|
|
|
|
|
class TofuOperationType(Enum):
|
|
# https://github.com/opentofu/opentofu/blob/main/internal/backend/operation_type.go
|
|
INVALID = "OperationTypeInvalid"
|
|
REFRESH = "OperationTypeRefresh"
|
|
PLAN = "OperationTypePlan"
|
|
APPLY = "OperationTypeApply"
|
|
|
|
|
|
class TofuInstanceState(CustomModel):
|
|
# TODO: Do better
|
|
model_config = ConfigDict(extra="allow")
|
|
|
|
|
|
class TofuInstanceStateLock(CustomModel):
|
|
model_config = ConfigDict(extra="allow")
|
|
ID: UUID
|
|
Operation: TofuOperationType
|
|
Info: str
|
|
Who: str
|
|
Version: str
|
|
Created: str
|
|
Path: str
|
|
|
|
|
|
class TofuInstanceSummary(CustomModel, IdMixin, TimestampMixin):
|
|
status: TofuInstanceStatus
|
|
status_changed_at: CustomDatetime
|
|
drift_checked_at: CustomDatetime | None
|
|
|
|
|
|
class TofuInstanceStatusChange(CustomModel):
|
|
instance_task_id: int
|
|
timestamp: datetime
|
|
old_status: TofuInstanceStatus
|
|
new_status: TofuInstanceStatus
|
|
|
|
|
|
class TofuInstanceTask(CustomModel, TimestampMixin):
|
|
id: int
|
|
task: TofuInstanceTaskType
|
|
status: TofuInstanceTaskStatus
|
|
start_time: datetime | None
|
|
end_time: datetime | None
|
|
|
|
|
|
class TofuInstanceDetail(CustomModel, IdMixin, TimestampMixin):
|
|
status: TofuInstanceStatus
|
|
configuration: dict[str, Any]
|
|
outputs: dict[str, Any] | None
|
|
plan: dict[str, Any] | None
|
|
status_changed_at: CustomDatetime
|
|
drift_checked_at: CustomDatetime | None
|
|
state_lock: TofuInstanceStateLock | None
|
|
tasks: list[TofuInstanceTask]
|
|
status_changes: list[TofuInstanceStatusChange]
|
|
|
|
|
|
class TofuInstanceCreate(CustomModel):
|
|
configuration: dict[str, Any]
|
|
password: str | None = None
|
|
|
|
|
|
class TofuInstanceUpdate(CustomModel):
|
|
configuration: dict[str, Any] | None = None
|
|
password: str | None = None
|