34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
import paramiko, json
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect('140.44.4.90', username='rancher', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10)
|
|
|
|
def run(cmd):
|
|
full_cmd = "echo Katzir476! | sudo -S sh -c 'export KUBECONFIG=/etc/rancher/rke2/rke2.yaml; PATH=$PATH:/var/lib/rancher/rke2/bin; " + cmd + "'"
|
|
stdin, stdout, stderr = c.exec_command(full_cmd)
|
|
return stdout.read().decode().strip()
|
|
|
|
print("=== Blockdevices on Harvester ===")
|
|
print(run("kubectl get blockdevices.harvesterhci.io -A -o wide"))
|
|
|
|
print("\n=== Longhorn storage on Harvester nodes ===")
|
|
out = run("kubectl get nodes.longhorn.io -n longhorn-system -o json")
|
|
data = json.loads(out)
|
|
total_max = 0
|
|
total_avail = 0
|
|
num_disks = 0
|
|
for n in data['items']:
|
|
disks = n.get('status', {}).get('diskStatus', {})
|
|
for d_name, d_val in disks.items():
|
|
num_disks += 1
|
|
total_max += d_val.get('storageMaximum', 0)
|
|
total_avail += d_val.get('storageAvailable', 0)
|
|
|
|
tib = total_max / (1024**4)
|
|
avail_tib = total_avail / (1024**4)
|
|
print(f"Harvester Disks: {num_disks}, Total Storage: {tib:.2f} TiB, Available: {avail_tib:.2f} TiB")
|
|
|
|
c.close()
|
|
|