76 lines
2.2 KiB
Python
76 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Lade die staged L3-Cutover-Config auf crs326-core (noch NICHT enablen).
|
|
|
|
Creds aus ~/.claude.json. Alle operativen Objekte in der rsc sind disabled=yes,
|
|
also bleibt der aktive Datenpfad unberührt.
|
|
"""
|
|
import json
|
|
import pathlib
|
|
import subprocess
|
|
import sys
|
|
|
|
CORE_IP = "10.40.41.211"
|
|
RSC = pathlib.Path(__file__).with_name("tp15-core-cutover-intended.rsc")
|
|
CLAUDE_JSON = pathlib.Path.home() / ".claude.json"
|
|
|
|
|
|
def load_core_creds():
|
|
cfg = json.loads(CLAUDE_JSON.read_text())
|
|
env = cfg.get("mcpServers", {}).get("mikromcp", {}).get("env", {})
|
|
user = env.get("CRS326_CORE_USER") or env.get("ROUTER_USER")
|
|
pw = env.get("CRS326_CORE_PASS") or env.get("ROUTER_PASS")
|
|
if not user or not pw:
|
|
raise SystemExit("CRS326_CORE_USER/PASS nicht in ~/.claude.json mikromcp.env gefunden")
|
|
return user, pw
|
|
|
|
|
|
def ssh_base(user, pw):
|
|
return [
|
|
"sshpass", "-p", pw,
|
|
"ssh",
|
|
"-o", "StrictHostKeyChecking=no",
|
|
"-o", "UserKnownHostsFile=/dev/null",
|
|
"-o", "PubkeyAuthentication=no",
|
|
f"{user}@{CORE_IP}",
|
|
]
|
|
|
|
|
|
def run_silent(base, cmd):
|
|
r = subprocess.run(base + [cmd], capture_output=True, text=True)
|
|
if r.returncode != 0:
|
|
out = (r.stdout + r.stderr).replace(pw, "***")
|
|
raise SystemExit(f"Befehl fehlgeschlagen (rc={r.returncode}):\n{out}")
|
|
return r
|
|
|
|
|
|
def main():
|
|
if not RSC.exists():
|
|
raise SystemExit(f"{RSC} fehlt")
|
|
user, pw = load_core_creds()
|
|
base = ssh_base(user, pw)
|
|
print(f"crs326-core L3-Cutover-Config laden ({RSC.name}) ...")
|
|
|
|
# 1) Datei auf Router kopieren
|
|
r = subprocess.run(
|
|
["sshpass", "-p", pw,
|
|
"scp",
|
|
"-o", "StrictHostKeyChecking=no",
|
|
"-o", "UserKnownHostsFile=/dev/null",
|
|
"-o", "PubkeyAuthentication=no",
|
|
str(RSC),
|
|
f"{user}@{CORE_IP}:{RSC.name}"],
|
|
capture_output=True, text=True,
|
|
)
|
|
if r.returncode != 0:
|
|
raise SystemExit(f"SCP fehlgeschlagen: {r.stderr.replace(pw, '***')}")
|
|
|
|
# 2) Import auslösen
|
|
run_silent(base, f'/import file-name="{RSC.name}"')
|
|
|
|
print(" Import abgeschlossen (staged / disabled).")
|
|
print(" Nächster Schritt: L2-Portplan + Cutover-Enable.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|