|
| 1 | +"""Models for host APIs.""" |
| 2 | + |
| 3 | +from dataclasses import dataclass |
| 4 | +from datetime import datetime |
| 5 | +from enum import StrEnum |
| 6 | + |
| 7 | +from .base import Request, ResponseData |
| 8 | +from .root import HostFeature |
| 9 | + |
| 10 | +# --- ENUMS ---- |
| 11 | + |
| 12 | + |
| 13 | +class ServiceState(StrEnum): |
| 14 | + """ServiceState type. |
| 15 | +
|
| 16 | + The service state is determined by systemd, not supervisor. The list below |
| 17 | + is pulled from `systemctl --state=help`. It may be incomplete and it may |
| 18 | + change based on the host. Therefore within a list of services there may be |
| 19 | + some with a state not in this list parsed as string. If you find this |
| 20 | + please create an issue or pr to get the state added. |
| 21 | + """ |
| 22 | + |
| 23 | + ACTIVE = "active" |
| 24 | + RELOADING = "reloading" |
| 25 | + INACTIVE = "inactive" |
| 26 | + FAILED = "failed" |
| 27 | + ACTIVATING = "activating" |
| 28 | + DEACTIVATING = "deactivating" |
| 29 | + MAINTENANCE = "maintenance" |
| 30 | + |
| 31 | + |
| 32 | +# --- OBJECTS ---- |
| 33 | + |
| 34 | + |
| 35 | +@dataclass(frozen=True, slots=True) |
| 36 | +class HostInfo(ResponseData): |
| 37 | + """HostInfo model.""" |
| 38 | + |
| 39 | + agent_version: str | None |
| 40 | + apparmor_version: str | None |
| 41 | + chassis: str | None |
| 42 | + virtualization: str | None |
| 43 | + cpe: str | None |
| 44 | + deployment: str | None |
| 45 | + disk_free: float |
| 46 | + disk_total: float |
| 47 | + disk_used: float |
| 48 | + disk_life_time: float |
| 49 | + features: list[HostFeature] |
| 50 | + hostname: str | None |
| 51 | + llmnr_hostname: str | None |
| 52 | + kernel: str | None |
| 53 | + operating_system: str | None |
| 54 | + timezone: str | None |
| 55 | + dt_utc: datetime | None |
| 56 | + dt_synchronized: bool | None |
| 57 | + use_ntp: bool | None |
| 58 | + startup_time: float | None |
| 59 | + boot_timestamp: int | None |
| 60 | + broadcast_llmnr: bool | None |
| 61 | + broadcast_mdns: bool | None |
| 62 | + |
| 63 | + |
| 64 | +@dataclass(frozen=True, slots=True) |
| 65 | +class ShutdownOptions(Request): |
| 66 | + """ShutdownOptions model.""" |
| 67 | + |
| 68 | + force: bool |
| 69 | + |
| 70 | + |
| 71 | +@dataclass(frozen=True, slots=True) |
| 72 | +class RebootOptions(Request): |
| 73 | + """RebootOptions model.""" |
| 74 | + |
| 75 | + force: bool |
| 76 | + |
| 77 | + |
| 78 | +@dataclass(frozen=True, slots=True) |
| 79 | +class HostOptions(Request): |
| 80 | + """HostOptions model.""" |
| 81 | + |
| 82 | + hostname: str |
| 83 | + |
| 84 | + |
| 85 | +@dataclass(frozen=True, slots=True) |
| 86 | +class Service(ResponseData): |
| 87 | + """Service model.""" |
| 88 | + |
| 89 | + name: str |
| 90 | + description: str |
| 91 | + state: ServiceState | str |
| 92 | + |
| 93 | + |
| 94 | +@dataclass(frozen=True, slots=True) |
| 95 | +class ServiceList(ResponseData): |
| 96 | + """ServiceList model.""" |
| 97 | + |
| 98 | + services: list[Service] |
0 commit comments