39 lines
1.6 KiB
Python
39 lines
1.6 KiB
Python
import paramiko
|
|
import time
|
|
|
|
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()
|
|
|
|
# Patch using kubectl patch with escaped json
|
|
patch_cmd = 'kubectl patch replica.longhorn.io pvc-4da99c48-f52e-4adf-9b4c-16e8878eb495-r-3a9069af -n longhorn-system --type=merge -p \'{"spec":{"salvageRequested":true}}\''
|
|
out, err = k8s(patch_cmd)
|
|
print("Patch 1:", out, err)
|
|
|
|
patch_cmd = 'kubectl patch replica.longhorn.io pvc-4da99c48-f52e-4adf-9b4c-16e8878eb495-r-593bd03f -n longhorn-system --type=merge -p \'{"spec":{"salvageRequested":true}}\''
|
|
out, err = k8s(patch_cmd)
|
|
print("Patch 2:", out, err)
|
|
|
|
patch_cmd = 'kubectl patch replica.longhorn.io pvc-4da99c48-f52e-4adf-9b4c-16e8878eb495-r-b5bbbcbf -n longhorn-system --type=merge -p \'{"spec":{"salvageRequested":true}}\''
|
|
out, err = k8s(patch_cmd)
|
|
print("Patch 3:", out, err)
|
|
|
|
time.sleep(5)
|
|
out, _ = k8s("kubectl get volume.longhorn.io pvc-4da99c48-f52e-4adf-9b4c-16e8878eb495 -n longhorn-system -o custom-columns=NAME:.metadata.name,STATE:.status.state,ROBUSTNESS:.status.robustness")
|
|
print("\nVolume status after patch:")
|
|
print(out)
|
|
|
|
# Check pod using this pvc
|
|
out, _ = k8s("kubectl get pods -n ai-stack -l app=glm-superexpert")
|
|
print("\nPod status:")
|
|
print(out)
|
|
|
|
c.close()
|
|
|