Skip to content

Commit

Permalink
Validate instance states during wait and clarify region logic.
Browse files Browse the repository at this point in the history
Add checks to ensure cluster states align with instance statuses during the wait operation, raising errors on mismatches. Enhance comments to explain how the region is inferred from project IDs due to the lack of direct region information retrieval in Nebius.
  • Loading branch information
SalikovAlex committed Jan 31, 2025
1 parent 0c25e4b commit 43c6500
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
17 changes: 16 additions & 1 deletion sky/provision/nebius/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,23 @@ def run_instances(region: str, cluster_name_on_cloud: str,

def wait_instances(region: str, cluster_name_on_cloud: str,
state: Optional[status_lib.ClusterStatus]) -> None:
del state
_wait_until_no_pending(region, cluster_name_on_cloud)
if state is not None:
if state == status_lib.ClusterStatus.UP:
stopped_instances = _filter_instances(region, cluster_name_on_cloud,
['STOPPED'])
if stopped_instances:
raise RuntimeError(
f'Cluster {cluster_name_on_cloud} is in UP state, but '
f'{len(stopped_instances)} instances are stopped.')
if state == status_lib.ClusterStatus.STOPPED:
running_instances = _filter_instances(region, cluster_name_on_cloud,
['RUNNIG'])

if running_instances:
raise RuntimeError(
f'Cluster {cluster_name_on_cloud} is in STOPPED state, but '
f'{len(running_instances)} instances are running.')


def stop_instances(
Expand Down
7 changes: 7 additions & 0 deletions sky/provision/nebius/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ def get_project_by_region(region: str) -> str:
service = nebius.iam().ProjectServiceClient(nebius.sdk())
projects = service.list(nebius.iam().ListProjectsRequest(
parent_id=nebius.get_tenant_id())).wait()
# To find a project in a specific region, we rely on the project ID to
# deduce the region, since there is currently no method to retrieve region
# information directly from the project. Additionally, there is only one
# project per region, and projects cannot be created at this time.
# The region is determined from the project ID using a region-specific
# identifier embedded in it.
# https://docs.nebius.com/overview/regions
for project in projects.items:
if region == 'eu-north1' and project.metadata.id[8:11] == 'e00':
return project.metadata.id
Expand Down

0 comments on commit 43c6500

Please sign in to comment.