Skip to content

Commit

Permalink
allow stopping Azure
Browse files Browse the repository at this point in the history
  • Loading branch information
suquark committed Feb 15, 2022
1 parent f931390 commit 43a8764
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
27 changes: 10 additions & 17 deletions prototype/sky/backends/cloud_vm_ray_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1562,22 +1562,8 @@ def teardown(self, handle: ResourceHandle, terminate: bool) -> None:
prev_status = global_user_state.get_status_from_cluster_name(
handle.cluster_name)
cluster_name = config['cluster_name']
if not terminate and not isinstance(cloud, (clouds.AWS, clouds.GCP)):
# FIXME: no mentions of cache_stopped_nodes in
# https://github.com/ray-project/ray/blob/master/python/ray/autoscaler/_private/_azure/node_provider.py
raise ValueError(
f'Stopping cluster {handle.cluster_name!r}: not supported on '
'non-AWS and non-GCP clusters yet. Try manually stopping, '
f'or terminate by: sky down {handle.cluster_name}')
if isinstance(cloud, clouds.Azure):
# Special handling because `ray down` is buggy with Azure.
# Set check=False to not error out on not found VMs.
backend_utils.run(
'az vm delete --yes --ids $(az vm list --query '
f'"[? contains(name, \'{cluster_name}\')].id" -o tsv)',
check=False)
elif (terminate and
prev_status == global_user_state.ClusterStatus.STOPPED):
if (terminate and
prev_status == global_user_state.ClusterStatus.STOPPED):
if isinstance(cloud, clouds.AWS):
# TODO (zhwu): Room for optimization. We can move these cloud
# specific handling to the cloud class.
Expand All @@ -1594,11 +1580,18 @@ def teardown(self, handle: ResourceHandle, terminate: bool) -> None:
f'aws ec2 terminate-instances --region {region} '
f'--instance-ids $({query_cmd})')
backend_utils.run(terminate_cmd, check=True)
elif isinstance(cloud, clouds.Azure):
# Special handling because `ray down` is buggy with Azure.
# Set check=False to not error out on not found VMs.
backend_utils.run(
'az vm delete --yes --ids $(az vm list --query '
f'"[? contains(name, \'{cluster_name}\')].id" -o tsv)',
check=False)
else:
# TODO(suquark,zongheng): Support deleting stopped GCP clusters.
# Tracked in issue #318.
logger.info(
f'Cannot terminate non-AWS cluster {cluster_name!r} '
f'Cannot terminate GCP cluster {cluster_name!r} '
'because it is STOPPED. \nTo fix: manually terminate in '
'the cloud\'s UI or '
f'`sky start {cluster_name}; sky down {cluster_name}` '
Expand Down
2 changes: 2 additions & 0 deletions prototype/sky/cloud_adaptors/azure.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Azure cli adaptor"""

# pylint: disable=import-outside-toplevel


def get_subscription_id() -> str:
"""Get the default subscription id."""
Expand Down

0 comments on commit 43a8764

Please sign in to comment.