53 lines
1.3 KiB
Python
53 lines
1.3 KiB
Python
"""Application service for the Agent Management read model."""
|
|
|
|
from app.agent_registry.models import (
|
|
AgentRegistryAgent,
|
|
AgentRegistryData,
|
|
AgentRegistrySite,
|
|
AgentRegistryZone,
|
|
)
|
|
|
|
|
|
class AgentRegistryService:
|
|
def __init__(self, repository):
|
|
self.repository = repository
|
|
|
|
def list_registry(self) -> AgentRegistryData:
|
|
rows = self.repository.list_registry()
|
|
|
|
sites = [
|
|
AgentRegistrySite(**row)
|
|
for row in rows["sites"]
|
|
]
|
|
|
|
zones = [
|
|
AgentRegistryZone(**row)
|
|
for row in rows["zones"]
|
|
]
|
|
|
|
agents: list[AgentRegistryAgent] = []
|
|
|
|
for row in rows["agents"]:
|
|
zone_id = row.get("agent_zone_id")
|
|
zone_enabled = row.get("agent_zone_enabled")
|
|
|
|
if zone_id is None:
|
|
routing_state = "unassigned"
|
|
elif zone_enabled is False:
|
|
routing_state = "disabled"
|
|
else:
|
|
routing_state = "assigned"
|
|
|
|
agents.append(
|
|
AgentRegistryAgent(
|
|
**row,
|
|
routing_state=routing_state,
|
|
)
|
|
)
|
|
|
|
return AgentRegistryData(
|
|
agents=agents,
|
|
sites=sites,
|
|
zones=zones,
|
|
)
|