File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ """
3+ Script to retrieve all clusters the user has access to.
4+
5+ This script displays cluster information including:
6+ - Cluster ID
7+ - Cluster Name (Prometheus-compatible identifier)
8+ - Display Name (human-readable)
9+ - Region
10+ """
11+
12+ import click
13+
14+ from centml .sdk .api import get_centml_client
15+
16+
17+ def get_clusters ():
18+ """Retrieve all accessible clusters."""
19+ with get_centml_client () as client :
20+ return client .get_clusters ().results
21+
22+
23+ def display_clusters (clusters ):
24+ """Display cluster information in a formatted table."""
25+ if not clusters :
26+ click .echo ("No clusters found." )
27+ return
28+
29+ click .echo (f"\n Found { len (clusters )} cluster(s)\n " )
30+
31+ for cluster in sorted (clusters , key = lambda x : x .id ):
32+ region = cluster .region if cluster .region else "N/A"
33+ click .echo (f"ID: { cluster .id } " )
34+ click .echo (f"Cluster Name: { cluster .cluster_name } " )
35+ click .echo (f"Display Name: { cluster .display_name } " )
36+ click .echo (f"Region: { region } " )
37+ click .echo ("-" * 40 )
38+
39+
40+ @click .command ()
41+ def main ():
42+ """Retrieve all clusters you have access to.
43+
44+ This script uses the centml CLI authentication,
45+ so make sure you are logged in to centml CLI before running this script.
46+
47+ \b
48+ Examples:
49+ python get_clusters.py
50+ """
51+ clusters = get_clusters ()
52+ display_clusters (clusters )
53+
54+
55+ if __name__ == "__main__" :
56+ main ()
Original file line number Diff line number Diff line change @@ -9,4 +9,4 @@ cryptography==44.0.1
99prometheus-client >= 0.20.0
1010scipy >= 1.6.0
1111scikit-learn >= 1.5.1
12- platform-api-python-client == 4.1.9
12+ platform-api-python-client == 4.6.0
You can’t perform that action at this time.
0 commit comments