Skip to content

Commit 3f90011

Browse files
worked on adding hardware instance mapping api to cli (#52)
1 parent 1f98394 commit 3f90011

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

centml/cli/cluster.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
from typing import Dict
23
import click
34
from tabulate import tabulate
45
import platform_api_client
@@ -20,8 +21,20 @@ def convert(self, value, param, ctx):
2021
return None # to avoid warning from lint for inconsistent return statements
2122

2223

23-
hw_to_id_map = {"small": 1000, "medium": 1001, "large": 1002}
24-
id_to_hw_map = {v: k for k, v in hw_to_id_map.items()}
24+
def get_hw_to_id_map():
25+
response = api.get_hardware_instances()
26+
27+
# Convert to list of dictionaries
28+
instances = [item.to_dict() for item in response]
29+
30+
# Initialize hashmap for hardware to id or vice versa mapping
31+
hw_to_id_map: Dict[str, int] = {}
32+
id_to_hw_map: Dict[str, str] = {}
33+
34+
for item in instances:
35+
hw_to_id_map[item["name"]] = item["id"]
36+
id_to_hw_map[item["id"]] = item["name"]
37+
return hw_to_id_map, id_to_hw_map
2538

2639

2740
depl_type_map = {
@@ -99,6 +112,9 @@ def get(type, id):
99112
ready_status = get_ready_status(deployment.status, state.service_status)
100113

101114
click.echo(f"The current status of Deployment #{id} is: {ready_status}.")
115+
116+
_, id_to_hw_map = get_hw_to_id_map()
117+
102118
click.echo(
103119
tabulate(
104120
[
@@ -144,6 +160,7 @@ def get(type, id):
144160

145161
# Define common deployment
146162
def common_options(func):
163+
hw_to_id_map, _ = get_hw_to_id_map()
147164
func = click.option("--name", "-n", prompt="Name", help="Name of the deployment")(func)
148165
func = click.option("--image", "-i", prompt="Image", help="Container image")(func)
149166
func = click.option(
@@ -214,6 +231,8 @@ def create_inference(ctx, **kwargs):
214231
command_args = kwargs.get("command_args")
215232
timeout = kwargs.get("timeout")
216233

234+
hw_to_id_map, _ = get_hw_to_id_map()
235+
217236
# Call the API function for creating infrence deployment
218237
resp = api.create_inference(
219238
name,
@@ -248,6 +267,8 @@ def create_compute(ctx, **kwargs):
248267
ssh_key = kwargs.get("ssh_key")
249268
hardware = kwargs.get("hardware")
250269

270+
hw_to_id_map, _ = get_hw_to_id_map()
271+
251272
# Call the API function for creating infrence deployment
252273
resp = api.create_compute(name, image, username, password, ssh_key, hw_to_id_map[hardware])
253274

centml/sdk/api.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,8 @@ def pause(id):
100100

101101
def resume(id):
102102
update_status(id, DeploymentStatus.ACTIVE)
103+
104+
105+
def get_hardware_instances():
106+
with get_api() as api:
107+
return api.get_hardware_instances_hardware_instances_get().results

0 commit comments

Comments
 (0)