Initial commit of AthonetTools

This commit is contained in:
2025-08-21 12:59:43 +00:00
commit cd932b8fcb
2483 changed files with 433999 additions and 0 deletions

29
services/combocore/ncm.py Normal file
View File

@@ -0,0 +1,29 @@
from typing import Tuple, Optional, List, Dict
from .client import ComboCoreClient
def get_routes(host: str, user: str, pwd: str, verify_ssl=False, timeout=10.0) -> List[Dict]:
cli = ComboCoreClient(host, user, pwd, verify_ssl, timeout)
return cli.get("/core/ncm/api/1/status/routes")
def derive_eth0_cidr_gw(routes: List[Dict]) -> Tuple[str, Optional[str]]:
gw = None
ip = None
masklen = None
for rt in routes:
if rt.get("family") == "inet" and rt.get("dst") == "default" and rt.get("dev") == "eth0":
gw = rt.get("gateway")
for rt in routes:
if rt.get("family") == "inet" and rt.get("dev") == "eth0":
if not ip and rt.get("prefsrc"):
ip = rt["prefsrc"]
dst = rt.get("dst", "")
if "/" in dst:
try:
masklen = int(dst.split("/", 1)[1])
except Exception:
pass
if ip and masklen is not None:
break
if not ip or masklen is None:
raise RuntimeError("Could not derive eth0 IP/prefix from routes.")
return f"{ip}/{masklen}", gw