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: Fix the issue that it can't query the SKU which with partially zones available #18939

Merged
merged 5 commits into from
Jul 29, 2021
Merged
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
21 changes: 19 additions & 2 deletions src/azure-cli/azure/cli/command_modules/vm/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,9 +1145,26 @@ def get_vm_details(cmd, resource_group_name, vm_name, include_user_data=False):
def list_skus(cmd, location=None, size=None, zone=None, show_all=None, resource_type=None):
from ._vm_utils import list_sku_info
result = list_sku_info(cmd.cli_ctx, location)
# pylint: disable=too-many-nested-blocks
if not show_all:
result = [x for x in result if not [y for y in (x.restrictions or [])
if y.reason_code == 'NotAvailableForSubscription']]
available_skus = []
for sku_info in result:
is_available = True
if sku_info.restrictions:
for restriction in sku_info.restrictions:
if restriction.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
# This SKU is not available only if all zones are restricted
if not (set(sku_info.location_info[0].zones or []) -
set(restriction.restriction_info.zones or [])):
is_available = False
break
if is_available:
available_skus.append(sku_info)
result = available_skus
if resource_type:
result = [x for x in result if x.resource_type.lower() == resource_type.lower()]
if size:
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,11 @@ def test_list_compute_skus_filter(self):
result = self.cmd('vm list-skus -l westus --resource-type disks').get_output_in_json()
self.assertTrue(result and len(result) == len([x for x in result if x['resourceType'] == 'disks']))

@AllowLargeResponse(size_kb=99999)
def test_list_compute_skus_partially_unavailable(self):
result = self.cmd('vm list-skus -l eastus --query "[?name==\'Standard_M64m\']"').get_output_in_json()
self.assertTrue(result and result[0]["restrictions"] and result[0]["restrictions"][0]["reasonCode"] == 'NotAvailableForSubscription')


class VMExtensionScenarioTest(ScenarioTest):

Expand Down