Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions centml/cli/cluster.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
from typing import Dict
import click
from tabulate import tabulate
import platform_api_client
Expand All @@ -20,8 +21,20 @@ def convert(self, value, param, ctx):
return None # to avoid warning from lint for inconsistent return statements


hw_to_id_map = {"small": 1000, "medium": 1001, "large": 1002}
id_to_hw_map = {v: k for k, v in hw_to_id_map.items()}
def get_hw_to_id_map():
response = api.get_hardware_instances()

# Convert to list of dictionaries
instances = [item.to_dict() for item in response]

# Initialize hashmap for hardware to id or vice versa mapping
hw_to_id_map: Dict[str, int] = {}
id_to_hw_map: Dict[str, str] = {}

for item in instances:
hw_to_id_map[item["name"]] = item["id"]
id_to_hw_map[item["id"]] = item["name"]
return hw_to_id_map, id_to_hw_map


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

click.echo(f"The current status of Deployment #{id} is: {ready_status}.")

_, id_to_hw_map = get_hw_to_id_map()

click.echo(
tabulate(
[
Expand Down Expand Up @@ -144,6 +160,7 @@ def get(type, id):

# Define common deployment
def common_options(func):
hw_to_id_map, _ = get_hw_to_id_map()
func = click.option("--name", "-n", prompt="Name", help="Name of the deployment")(func)
func = click.option("--image", "-i", prompt="Image", help="Container image")(func)
func = click.option(
Expand Down Expand Up @@ -214,6 +231,8 @@ def create_inference(ctx, **kwargs):
command_args = kwargs.get("command_args")
timeout = kwargs.get("timeout")

hw_to_id_map, _ = get_hw_to_id_map()

# Call the API function for creating infrence deployment
resp = api.create_inference(
name,
Expand Down Expand Up @@ -248,6 +267,8 @@ def create_compute(ctx, **kwargs):
ssh_key = kwargs.get("ssh_key")
hardware = kwargs.get("hardware")

hw_to_id_map, _ = get_hw_to_id_map()

# Call the API function for creating infrence deployment
resp = api.create_compute(name, image, username, password, ssh_key, hw_to_id_map[hardware])

Expand Down
5 changes: 5 additions & 0 deletions centml/sdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,8 @@ def pause(id):

def resume(id):
update_status(id, DeploymentStatus.ACTIVE)


def get_hardware_instances():
with get_api() as api:
return api.get_hardware_instances_hardware_instances_get().results