From f9d34652d7a25e563d0a04b67542b6f1842fa46f Mon Sep 17 00:00:00 2001 From: Honglin Cao Date: Wed, 11 Feb 2026 11:15:03 -0500 Subject: [PATCH] create get cluster.py --- examples/sdk/get_clusters.py | 56 ++++++++++++++++++++++++++++++++++++ requirements.txt | 2 +- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 examples/sdk/get_clusters.py diff --git a/examples/sdk/get_clusters.py b/examples/sdk/get_clusters.py new file mode 100644 index 0000000..b7c0f19 --- /dev/null +++ b/examples/sdk/get_clusters.py @@ -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() diff --git a/requirements.txt b/requirements.txt index e949a10..c3b4961 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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