Skip to content

Commit b168feb

Browse files
defer api call during the initialization phase for get hardware instances (#62)
1 parent 02b0bff commit b168feb

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

centml/cli/cluster.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,18 @@ def get_hw_to_id_map():
4040
# # Hardware pricing tier that loads choices dynamically
4141
class HardwarePricingTier(click.ParamType):
4242
def __init__(self):
43-
self.hw_to_id_map, self.id_to_hw_map = get_hw_to_id_map()
44-
self.choices = list(self.hw_to_id_map.keys())
43+
self.hw_to_id_map = None
44+
self.id_to_hw_map = None
45+
self.choices = None
46+
47+
def initialize_maps(self):
48+
if self.hw_to_id_map is None or self.id_to_hw_map is None or self.choices is None:
49+
self.hw_to_id_map, self.id_to_hw_map = get_hw_to_id_map()
50+
self.choices = list(self.hw_to_id_map.keys())
4551

4652
def convert(self, value, param, ctx):
53+
# calling initialize_maps to defer api call during initialization phase
54+
self.initialize_maps()
4755
if value not in self.choices:
4856
self.fail(f"{value} is not a valid choice. Available choices are: {', '.join(self.choices)}", param, ctx)
4957
return value

0 commit comments

Comments
 (0)