Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Michaelvll committed Jul 1, 2024
1 parent 4f7cced commit 94f7c61
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions sky/provision/azure/instance.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Azure instance provisioning."""
import logging
from multiprocessing import pool
import typing
from typing import Any, Callable, Dict, List, Optional

from sky import exceptions
Expand All @@ -10,6 +11,9 @@
from sky.utils import common_utils
from sky.utils import ux_utils

if typing.TYPE_CHECKING:
from azure.mgmt import compute as azure_compute

logger = sky_logging.init_logger(__name__)

# Suppress noisy logs from Azure SDK. Reference:
Expand All @@ -21,6 +25,8 @@
TAG_RAY_CLUSTER_NAME = 'ray-cluster-name'
TAG_RAY_NODE_KIND = 'ray-node-type'

_RESOURCE_GROUP_NOT_FOUND_ERROR_MESSAGE = 'ResourceGroupNotFound'


def get_azure_sdk_function(client: Any, function_name: str) -> Callable:
"""Retrieve a callable function from Azure SDK client object.
Expand Down Expand Up @@ -99,7 +105,8 @@ def cleanup_ports(
del cluster_name_on_cloud, ports, provider_config # Unused.


def _get_vm_status(compute_client, vm_name: str, resource_group: str) -> str:
def _get_vm_status(compute_client: 'azure_compute.ComputeManagementClient',
vm_name: str, resource_group: str) -> str:
instance = compute_client.virtual_machines.instance_view(
resource_group_name=resource_group, vm_name=vm_name).as_dict()
for status in instance['statuses']:
Expand All @@ -115,8 +122,9 @@ def _get_vm_status(compute_client, vm_name: str, resource_group: str) -> str:
raise ValueError(f'Failed to get status for VM {vm_name}')


def _filter_instances(compute_client, filters: Dict[str, str],
resource_group: str) -> List[Any]:
def _filter_instances(compute_client: 'azure_compute.ComputeManagementClient',
filters: Dict[str,
str], resource_group: str) -> List[Any]:

def match_tags(vm):
for k, v in filters.items():
Expand All @@ -130,7 +138,7 @@ def match_tags(vm):
vms = list_virtual_machines(resource_group_name=resource_group)
nodes = list(filter(match_tags, vms))
except azure.exceptions().ResourceNotFoundError as e:
if 'ResourceGroupNotFound' in str(e):
if _RESOURCE_GROUP_NOT_FOUND_ERROR_MESSAGE in str(e):
return []
raise
return nodes
Expand Down Expand Up @@ -163,7 +171,8 @@ def query_instances(
'Migrating': status_lib.ClusterStatus.INIT,
'Deleting': None,
# Succeeded in provisioning state means the VM is provisioned but not
# necessarily running.
# necessarily running. We exclude Succeeded state here, and the caller
# should determine the status of the VM based on the power state.
# 'Succeeded': status_lib.ClusterStatus.UP,
}

Expand Down

0 comments on commit 94f7c61

Please sign in to comment.