31 lines
978 B
Python
31 lines
978 B
Python
import paramiko
|
|
import requests
|
|
import json
|
|
import urllib3
|
|
urllib3.disable_warnings()
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect('140.44.4.11', username='root', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10)
|
|
|
|
name = 'kubeconfig-u-aqzkufonck4hmbd'
|
|
_, o, _ = c.exec_command(f'kubectl get tokens.management.cattle.io {name} -o json')
|
|
data = json.loads(o.read().decode())
|
|
token = data.get('token')
|
|
|
|
full_key = f"{name}:{token}"
|
|
headers = {"Authorization": f"Bearer {full_key}"}
|
|
r = requests.get("https://aerodrome.snarfnet.net/v3/clusters", headers=headers, verify=False, timeout=10)
|
|
|
|
for cl in r.json().get('data', []):
|
|
name = cl.get('name')
|
|
cid = cl.get('id')
|
|
state = cl.get('state')
|
|
cap = cl.get('capacity', {})
|
|
alloc = cl.get('allocatable', {})
|
|
print(f"=== Cluster: {name} (ID: {cid}, State: {state}) ===")
|
|
print(" Capacity:", cap)
|
|
print(" Allocatable:", alloc)
|
|
|
|
c.close()
|