11import sys
2+ from typing import Dict
23import click
34from tabulate import tabulate
45import 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
2740depl_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
146162def 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
0 commit comments