feat(host-agent): add control plane client

This commit is contained in:
2026-07-12 18:44:18 +08:00
parent 1e10d5aa95
commit f6bc8f6b98
4 changed files with 335 additions and 5 deletions
+31 -4
View File
@@ -19,16 +19,21 @@ class HostAgentConfig:
poll_timeout_seconds: float = 20.0
retry_backoff_seconds: float = 1.0
max_retry_backoff_seconds: float = 30.0
max_retry_attempts: int = 5
def load_host_agent_config(
env: Mapping[str, str] | None = None,
) -> HostAgentConfig:
values = os.environ if env is None else env
control_plane_url = values.get(
"HOST_AGENT_CONTROL_PLANE_URL",
"http://127.0.0.1:8001",
).strip().rstrip("/")
control_plane_url = (
values.get(
"HOST_AGENT_CONTROL_PLANE_URL",
"http://127.0.0.1:8001",
)
.strip()
.rstrip("/")
)
parsed_url = urlparse(control_plane_url)
if parsed_url.scheme not in {"http", "https"} or not parsed_url.netloc:
raise HostAgentConfigurationError(
@@ -66,6 +71,11 @@ def load_host_agent_config(
"HOST_AGENT_MAX_RETRY_BACKOFF_SECONDS",
30.0,
),
max_retry_attempts=_positive_int(
values,
"HOST_AGENT_MAX_RETRY_ATTEMPTS",
5,
),
)
if config.max_retry_backoff_seconds < config.retry_backoff_seconds:
raise HostAgentConfigurationError(
@@ -89,3 +99,20 @@ def _positive_float(
if value <= 0:
raise HostAgentConfigurationError(f"{name} must be greater than zero")
return value
def _positive_int(
values: Mapping[str, str],
name: str,
default: int,
) -> int:
raw_value = values.get(name)
if raw_value is None:
return default
try:
value = int(raw_value)
except ValueError as exc:
raise HostAgentConfigurationError(f"{name} must be an integer") from exc
if value <= 0:
raise HostAgentConfigurationError(f"{name} must be greater than zero")
return value