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

{Compute} az vm list-skus: Migrate to AAZ #31024

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/azure-cli/azure/cli/command_modules/vm/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def transform_sku_for_table_output(skus):
reason += ', type: ' + x['type']
if x['restrictionInfo']['locations']:
reason += ', locations: ' + ','.join(x['restrictionInfo']['locations'])
if x['restrictionInfo']['zones']:
if x['restrictionInfo'].get('zones', None):
reason += ', zones: ' + ','.join(x['restrictionInfo']['zones'])
reasons.append(reason)
order_dict['restrictions'] = str(reasons) if len(reasons) > 1 else reasons[0]
Expand Down
6 changes: 3 additions & 3 deletions src/azure-cli/azure/cli/command_modules/vm/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,11 @@ def _validate_location(cmd, namespace, zone_info, size_info):
get_default_location_from_resource_group(cmd, namespace)
if zone_info and size_info:
sku_infos = list_sku_info(cmd.cli_ctx, namespace.location)
temp = next((x for x in sku_infos if x.name.lower() == size_info.lower()), None)
temp = next((x for x in sku_infos if x['name'].lower() == size_info.lower()), None)
# For Stack (compute - 2017-03-30), Resource_sku doesn't implement location_info property
if not hasattr(temp, 'location_info'):
if not temp.get('locationInfo', None):
return
if not temp or not [x for x in (temp.location_info or []) if x.zones]:
if not temp or not [x for x in temp.get('locationInfo', []) if x.get('zones', None)]:
raise CLIError("{}'s location can't be used to create the VM/VMSS because availability zone is not yet "
"supported. Please use '--location' to specify a capable one. 'az vm list-skus' can be "
"used to find such locations".format(namespace.resource_group_name))
Expand Down
22 changes: 11 additions & 11 deletions src/azure-cli/azure/cli/command_modules/vm/_vm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,18 @@ def get_key_vault_base_url(cli_ctx, vault_name):


def list_sku_info(cli_ctx, location=None):
from ._client_factory import _compute_client_factory
from .aaz.latest.vm import ListSkus as _ListSkus

def _match_location(loc, locations):
return next((x for x in locations if x.lower() == loc.lower()), None)

client = _compute_client_factory(cli_ctx)
result = client.resource_skus.list()
result = _ListSkus(cli_ctx=cli_ctx)(command_args={})
if location:
result = [r for r in result if _match_location(location, r.locations)]
result = [r for r in result if _match_location(location, r['locations'])]
return result


# pylint: disable=line-too-long
def is_sku_available(cmd, sku_info, zone):
"""
The SKU is unavailable in the following cases:
Expand All @@ -140,19 +140,19 @@ def is_sku_available(cmd, sku_info, zone):
is_available = True
is_restrict_zone = False
is_restrict_location = False
if not sku_info.restrictions:
if not sku_info.get('restrictions', []):
return is_available
for restriction in sku_info.restrictions:
if restriction.reason_code == 'NotAvailableForSubscription':
for restriction in sku_info['restrictions']:
if restriction.get('reason_code', '') == 'NotAvailableForSubscription':
# The attribute location_info is not supported in versions 2017-03-30 and earlier
if cmd.supported_api_version(max_api='2017-03-30'):
is_available = False
break
if restriction.type == 'Zone' and not (
set(sku_info.location_info[0].zones or []) - set(restriction.restriction_info.zones or [])):
if restriction['type'] == 'Zone' and not (
set(sku_info['location_info'][0].get('zones', [])) - set(restriction['restriction_info'].get('zones', []))):
is_restrict_zone = True
if restriction.type == 'Location' and (
sku_info.location_info[0].location in (restriction.restriction_info.locations or [])):
if restriction['type'] == 'Location' and (
sku_info['location_info'][0]['location'] in (restriction['restriction_info'].get('locations', []))):
is_restrict_location = True

if is_restrict_location or (is_restrict_zone and zone):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from ._deallocate import *
from ._generalize import *
from ._list_sizes import *
from ._list_skus import *
from ._list_vm_resize_options import *
from ._perform_maintenance import *
from ._reapply import *
Expand Down
Loading
Loading