diff --git a/sky/provision/nebius/instance.py b/sky/provision/nebius/instance.py index 18ed077083e..1983f7acaf5 100644 --- a/sky/provision/nebius/instance.py +++ b/sky/provision/nebius/instance.py @@ -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( diff --git a/sky/provision/nebius/utils.py b/sky/provision/nebius/utils.py index 40b89c9e5e1..5a828bc2eb9 100644 --- a/sky/provision/nebius/utils.py +++ b/sky/provision/nebius/utils.py @@ -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