Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated azure.common usages #3466

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions sky/adaptors/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# pylint: disable=import-outside-toplevel
import functools
import json
import subprocess
import threading

from sky.adaptors import common
Expand All @@ -15,18 +17,31 @@
_session_creation_lock = threading.RLock()


@common.load_lazy_modules(modules=_LAZY_MODULES)
def _run_output(cmd):
proc = subprocess.run(cmd,
shell=True,
check=True,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE)
return proc.stdout.decode('ascii')
Programmerino marked this conversation as resolved.
Show resolved Hide resolved


# There is no programmatic way to get current account details anymore.
# https://github.com/Azure/azure-sdk-for-python/issues/21561


def _get_account():
return json.loads(_run_output('az account show -o json'))


def get_subscription_id() -> str:
"""Get the default subscription id."""
from azure.common import credentials
return credentials.get_cli_profile().get_subscription_id()
return _get_account()['id']


@common.load_lazy_modules(modules=_LAZY_MODULES)
def get_current_account_user() -> str:
"""Get the default account user."""
from azure.common import credentials
return credentials.get_cli_profile().get_current_account_user()
return _get_account()['user']['name']


@common.load_lazy_modules(modules=_LAZY_MODULES)
Expand Down
10 changes: 6 additions & 4 deletions sky/skylet/providers/azure/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
import time
from typing import Any, Callable

from azure.common.credentials import get_cli_profile
from azure.identity import AzureCliCredential
from azure.mgmt.network import NetworkManagementClient
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.resource import ResourceManagementClient, SubscriptionClient
from azure.mgmt.resource.resources.models import DeploymentMode

from sky.utils import common_utils
Expand Down Expand Up @@ -50,12 +49,15 @@ def _configure_resource_group(config):
# TODO: look at availability sets
# https://docs.microsoft.com/en-us/azure/virtual-machines/windows/tutorial-availability-sets
subscription_id = config["provider"].get("subscription_id")
if subscription_id is None:
subscription_id = get_cli_profile().get_subscription_id()
# Increase the timeout to fix the Azure get-access-token (used by ray azure
# node_provider) timeout issue.
# Tracked in https://github.com/Azure/azure-cli/issues/20404#issuecomment-1249575110
credentials = AzureCliCredential(process_timeout=30)

if subscription_id is None:
subscription_client = SubscriptionClient(credentials)
Programmerino marked this conversation as resolved.
Show resolved Hide resolved
subscription_id = next(subscription_client.subscriptions.list()).subscription_id
Programmerino marked this conversation as resolved.
Show resolved Hide resolved

resource_client = ResourceManagementClient(credentials, subscription_id)
config["provider"]["subscription_id"] = subscription_id
logger.info("Using subscription id: %s", subscription_id)
Expand Down
Loading