Files
SnarfCode/scripts/check_lh_recovery.py

35 lines
1.4 KiB
Python

import paramiko
import json
SSH_KEY = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet"
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("140.44.4.90", username="rancher", key_filename=SSH_KEY, timeout=10)
def k8s(cmd):
full_cmd = f"echo Katzir476! | sudo -S sh -c 'export KUBECONFIG=/etc/rancher/rke2/rke2.yaml; PATH=$PATH:/var/lib/rancher/rke2/bin; {cmd}'"
_, o, e = c.exec_command(full_cmd)
return o.read().decode().strip(), e.read().decode().strip()
print("Checking Longhorn nodes disk conditions:")
out, _ = k8s("kubectl get nodes.longhorn.io -n longhorn-system -o json")
data = json.loads(out)
for item in data.get("items", []):
name = item["metadata"]["name"]
print(f"\nNode: {name}")
for dname, dstat in item.get("status", {}).get("diskStatus", {}).items():
conds = {c.get("type"): c.get("status") for c in dstat.get("conditions", [])}
storage_avail = dstat.get("storageAvailable", 0) / (1024**3)
print(f" {dname}: Ready={conds.get('Ready')}, Schedulable={conds.get('Schedulable')}, Avail={storage_avail:.1f} GB")
print("\nLonghorn Volumes Status:")
out, _ = k8s("kubectl get volumes.longhorn.io -n longhorn-system -o custom-columns=NAME:.metadata.name,STATE:.status.state,ROBUSTNESS:.status.robustness")
print(out)
print("\nAI-stack pods:")
out, _ = k8s("kubectl get pods -n ai-stack")
print(out)
c.close()