feat: add config manager module with YAML loading for settings and services

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-15 08:57:32 +00:00
parent f1c20c0461
commit 2158dddb09
3 changed files with 137 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
from pathlib import Path
from typing import Any
import yaml
class ConfigManager:
def __init__(self, settings_path: str, services_path: str):
self._settings_path = settings_path
self._services_path = services_path
self._settings: dict[str, Any] = {}
self._services: dict[str, Any] = {}
def _load_yaml(self, path: str) -> dict[str, Any]:
p = Path(path)
if not p.exists():
return {}
with open(p) as f:
return yaml.safe_load(f) or {}
def get_settings(self) -> dict[str, Any]:
if not self._settings:
self._settings = self._load_yaml(self._settings_path)
return self._settings
def get_nodes(self) -> list[dict[str, Any]]:
if not self._services:
self._services = self._load_yaml(self._services_path)
return self._services.get("nodes", [])
def get_node_by_ip(self, ip: str) -> dict[str, Any] | None:
for node in self.get_nodes():
if node.get("ip") == ip:
return node
return None
def get_network_scan_config(self) -> dict[str, Any]:
if not self._services:
self._services = self._load_yaml(self._services_path)
return self._services.get("network_scan", {})
def reload(self) -> None:
self._settings = {}
self._services = {}