Skip to content

Commit 4e6fa90

Browse files
authored
Add in example script to get cluster (#120)
1 parent 3660c45 commit 4e6fa90

2 files changed

Lines changed: 57 additions & 1 deletion

File tree

examples/sdk/get_clusters.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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"\nFound {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()

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ cryptography==44.0.1
99
prometheus-client>=0.20.0
1010
scipy>=1.6.0
1111
scikit-learn>=1.5.1
12-
platform-api-python-client==4.1.9
12+
platform-api-python-client==4.6.0

0 commit comments

Comments
 (0)