Skip to content

Commit 0468540

Browse files
committed
Add CLI/SDK support for cluster capacity
1 parent 1962a4f commit 0468540

3 files changed

Lines changed: 40 additions & 1 deletion

File tree

‎centml/cli/cluster.py‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,38 @@ def resume(id):
232232
with get_centml_client() as cclient:
233233
cclient.resume(id)
234234
click.echo("Deployment has been resumed")
235+
236+
237+
@click.command(help="Show GPU capacity across clusters")
238+
@click.option("--cluster-id", type=int, default=None, help="Filter to a specific cluster")
239+
@handle_exception
240+
def capacity(cluster_id):
241+
with get_centml_client() as cclient:
242+
clusters = cclient.get_capacity(cluster_id)
243+
244+
if clusters is None:
245+
click.echo("No accelerator capacity available")
246+
return
247+
248+
rows = []
249+
for cluster in clusters:
250+
for gpu in cluster.gpu_types:
251+
utilization = (gpu.used_gpus / gpu.total_gpus * 100) if gpu.total_gpus > 0 else 0
252+
rows.append(
253+
[
254+
cluster.cluster_name,
255+
gpu.gpu_type,
256+
gpu.used_gpus,
257+
gpu.total_gpus,
258+
f"{utilization:.1f}%",
259+
]
260+
)
261+
262+
click.echo(
263+
tabulate(
264+
rows,
265+
headers=["Cluster", "GPU Type", "Used", "Total", "Utilization"],
266+
tablefmt="rounded_outline",
267+
disable_numparse=True,
268+
)
269+
)

‎centml/cli/main.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import click
22

33
from centml.cli.login import login, logout
4-
from centml.cli.cluster import ls, get, delete, pause, resume
4+
from centml.cli.cluster import ls, get, delete, pause, resume, capacity
55

66

77
@click.group()
@@ -47,6 +47,7 @@ def ccluster():
4747
ccluster.add_command(delete)
4848
ccluster.add_command(pause)
4949
ccluster.add_command(resume)
50+
ccluster.add_command(capacity)
5051

5152

5253
cli.add_command(ccluster, name="cluster")

‎centml/sdk/api.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ def invite_user(self, email: str):
145145
request = InviteUserRequest(email=email)
146146
return self._api.invite_user_organizations_invite_post(request)
147147

148+
def get_capacity(self, cluster_id=None):
149+
return self._api.list_cluster_capacity_capacity_get(cluster_id=cluster_id).results
150+
148151

149152
@contextmanager
150153
def get_centml_client():

0 commit comments

Comments
 (0)