# services/state.py from pathlib import Path import json STATE_FILE = Path("system_info.json") def load_state(): if STATE_FILE.exists(): return json.loads(STATE_FILE.read_text() or "{}") return {} def save_state(d: dict): STATE_FILE.write_text(json.dumps(d, indent=2)) def set_target_ip(ip: str): st = load_state() st["target_host_ip"] = ip save_state(st) def get_target_ip() -> str | None: return load_state().get("target_host_ip") def set_mgmt_info(cidr: str, gw: str): """Persist the current DHCP values we discovered for eth0 so we can render static OAM later.""" st = load_state() st["mgmt"] = {"cidr": cidr, "gw": gw} save_state(st) def get_mgmt_info() -> dict: """Return {'cidr': 'x.x.x.x/yy', 'gw': 'x.x.x.x'} if previously captured, else {}.""" return load_state().get("mgmt") or {}