Skip to content

Commit 3724532

Browse files
authored
Added price to sky status (skypilot-org#561)
* Added price to sky status * put region and hourly price behind -a in sky status * removed whitespace * cache cluster region * some touches + added computation to constructor * forgot one fix * formatting
1 parent b1bf052 commit 3724532

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

sky/backends/cloud_vm_ray_backend.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -621,10 +621,11 @@ def _yield_region_zones(self, to_provision: 'resources_lib.Resources',
621621

622622
if prev_resources is not None and cloud.is_same_cloud(
623623
prev_resources.cloud):
624-
if type(cloud) in (clouds.AWS, clouds.GCP):
624+
if cloud.is_same_cloud(sky.GCP()) or cloud.is_same_cloud(
625+
sky.AWS()):
625626
region = config['provider']['region']
626627
zones = config['provider']['availability_zone']
627-
elif isinstance(cloud, clouds.Azure):
628+
elif cloud.is_same_cloud(sky.Azure()):
628629
region = config['provider']['location']
629630
zones = None
630631
else:
@@ -1135,6 +1136,7 @@ def __init__(
11351136
self.launched_resources = launched_resources
11361137
self.tpu_create_script = tpu_create_script
11371138
self.tpu_delete_script = tpu_delete_script
1139+
self._find_cluster_region()
11381140

11391141
def __repr__(self):
11401142
return (f'ResourceHandle('
@@ -1150,6 +1152,21 @@ def __repr__(self):
11501152
def get_cluster_name(self):
11511153
return self.cluster_name
11521154

1155+
def _find_cluster_region(self):
1156+
config = backend_utils.read_yaml(self.cluster_yaml)
1157+
provider = config['provider']
1158+
cloud = self.launched_resources.cloud
1159+
if cloud.is_same_cloud(sky.Azure()):
1160+
self.cluster_region = provider['location']
1161+
elif cloud.is_same_cloud(sky.GCP()) or cloud.is_same_cloud(
1162+
sky.AWS()):
1163+
self.cluster_region = provider['region']
1164+
1165+
def get_cluster_region(self):
1166+
if not hasattr(self, 'cluster_region'):
1167+
self._find_cluster_region()
1168+
return self.cluster_region
1169+
11531170
def __init__(self):
11541171
self.run_timestamp = backend_utils.get_run_timestamp()
11551172
self.log_dir = os.path.join(SKY_LOGS_DIRECTORY, self.run_timestamp)

sky/cli.py

+24-4
Original file line numberDiff line numberDiff line change
@@ -828,14 +828,22 @@ def status(all: bool, refresh: bool): # pylint: disable=redefined-builtin
828828
# TODO(zhwu): Update the information for auto-stop clusters.
829829
show_all = all
830830
clusters_status = backend_utils.get_clusters(refresh)
831-
cluster_table = util_lib.create_table([
831+
columns = [
832832
'NAME',
833833
'LAUNCHED',
834834
'RESOURCES',
835835
'STATUS',
836836
'AUTOSTOP',
837837
'COMMAND',
838-
])
838+
]
839+
840+
if all:
841+
columns.extend([
842+
'HOURLY_PRICE',
843+
'REGION',
844+
])
845+
846+
cluster_table = util_lib.create_table(columns)
839847

840848
for cluster_status in clusters_status:
841849
launched_at = cluster_status['launched_at']
@@ -858,7 +866,7 @@ def status(all: bool, refresh: bool): # pylint: disable=redefined-builtin
858866
if cluster_status['autostop'] >= 0:
859867
# TODO(zhwu): check the status of the autostop cluster.
860868
autostop_str = str(cluster_status['autostop']) + ' min'
861-
cluster_table.add_row([
869+
row = [
862870
# NAME
863871
cluster_status['name'],
864872
# LAUNCHED
@@ -872,7 +880,19 @@ def status(all: bool, refresh: bool): # pylint: disable=redefined-builtin
872880
# COMMAND
873881
cluster_status['last_use']
874882
if show_all else _truncate_long_string(cluster_status['last_use']),
875-
])
883+
]
884+
if all:
885+
hourly_cost = handle.launched_resources.get_cost(3600) \
886+
* handle.launched_nodes
887+
price_str = f'$ {hourly_cost:.3f}'
888+
region = handle.get_cluster_region()
889+
row.extend([
890+
# HOURLY PRICE
891+
price_str,
892+
# REGION
893+
region,
894+
])
895+
cluster_table.add_row(row)
876896
if clusters_status:
877897
click.echo(cluster_table)
878898
else:

0 commit comments

Comments
 (0)