Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions examples/sdk/get_clusters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python3
"""
Script to retrieve all clusters the user has access to.

This script displays cluster information including:
- Cluster ID
- Cluster Name (Prometheus-compatible identifier)
- Display Name (human-readable)
- Region
"""

import click

from centml.sdk.api import get_centml_client


def get_clusters():
"""Retrieve all accessible clusters."""
with get_centml_client() as client:
return client.get_clusters().results


def display_clusters(clusters):
"""Display cluster information in a formatted table."""
if not clusters:
click.echo("No clusters found.")
return

click.echo(f"\nFound {len(clusters)} cluster(s)\n")

for cluster in sorted(clusters, key=lambda x: x.id):
region = cluster.region if cluster.region else "N/A"
click.echo(f"ID: {cluster.id}")
click.echo(f"Cluster Name: {cluster.cluster_name}")
click.echo(f"Display Name: {cluster.display_name}")
click.echo(f"Region: {region}")
click.echo("-" * 40)


@click.command()
def main():
"""Retrieve all clusters you have access to.

This script uses the centml CLI authentication,
so make sure you are logged in to centml CLI before running this script.

\b
Examples:
python get_clusters.py
"""
clusters = get_clusters()
display_clusters(clusters)


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ cryptography==44.0.1
prometheus-client>=0.20.0
scipy>=1.6.0
scikit-learn>=1.5.1
platform-api-python-client==4.1.9
platform-api-python-client==4.6.0
Loading