Files
SnarfCode/scripts/check_cluster_tokens.py

26 lines
916 B
Python

import paramiko
import sys
import yaml
sys.stdout.reconfigure(encoding='utf-8')
key_path = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet"
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect("140.44.4.11", username="root", key_filename=key_path, timeout=10)
stdin, stdout, stderr = client.exec_command("KUBECONFIG=/etc/rancher/k3s/k3s.yaml kubectl get clusterregistrationtokens.management.cattle.io -A -o yaml")
data = yaml.safe_load(stdout.read().decode('utf-8'))
client.close()
for item in data.get('items', []):
cluster = item.get('spec', {}).get('clusterName')
token = item.get('status', {}).get('token')
cmd = item.get('status', {}).get('command')
manifest_url = item.get('status', {}).get('manifestUrl')
print(f"\nCluster: {cluster}")
print(f"Token: {token}")
print(f"Command: {cmd}")
print(f"Manifest URL: {manifest_url}")