Files
buryan-infra/ops/scripts/fix_vendor_domains.py
2026-11-18 16:59:28 +03:00

28 lines
1008 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""Нормализовать domain=vcs у не-Yealink веток (кроме телефонии)."""
import glob
import os
import shutil
import time
import yaml
BASE = "/opt/work-hub/compat"
paths = [os.path.join(BASE, "catalog.yaml")] + sorted(glob.glob(os.path.join(BASE, "catalog-*.yaml")))
paths.append("/root/buryan-infra/ops/combine/catalog-p0-2026-11-18.yaml")
for p in paths:
if not os.path.exists(p):
continue
d = yaml.safe_load(open(p, encoding="utf-8"))
devs = d.get("devices") or []
n = 0
for x in devs:
if x.get("vendor") == "yealink":
continue
if x.get("domain") in ("", "unknown", None) and x.get("role") not in ("phone", "headset"):
x["domain"] = "vcs"
n += 1
if n:
shutil.copy2(p, p + ".bak-domain-" + time.strftime("%Y%m%d-%H%M%S"))
yaml.safe_dump(d, open(p, "w", encoding="utf-8"), allow_unicode=True, sort_keys=False)
print(os.path.basename(p), "fixed", n)