Skip to content

Commit f20811c

Browse files
committed
migrate
1 parent 3c2e1fb commit f20811c

File tree

11 files changed

+387
-46
lines changed

11 files changed

+387
-46
lines changed

src/azure-cli/azure/cli/command_modules/vm/_format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def transform_sku_for_table_output(skus):
9191
reason += ', type: ' + x['type']
9292
if x['restrictionInfo']['locations']:
9393
reason += ', locations: ' + ','.join(x['restrictionInfo']['locations'])
94-
if x['restrictionInfo']['zones']:
94+
if x['restrictionInfo'].get('zones', None):
9595
reason += ', zones: ' + ','.join(x['restrictionInfo']['zones'])
9696
reasons.append(reason)
9797
order_dict['restrictions'] = str(reasons) if len(reasons) > 1 else reasons[0]

src/azure-cli/azure/cli/command_modules/vm/_validators.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,11 @@ def _validate_location(cmd, namespace, zone_info, size_info):
359359
get_default_location_from_resource_group(cmd, namespace)
360360
if zone_info and size_info:
361361
sku_infos = list_sku_info(cmd.cli_ctx, namespace.location)
362-
temp = next((x for x in sku_infos if x.name.lower() == size_info.lower()), None)
362+
temp = next((x for x in sku_infos if x['name'].lower() == size_info.lower()), None)
363363
# For Stack (compute - 2017-03-30), Resource_sku doesn't implement location_info property
364-
if not hasattr(temp, 'location_info'):
364+
if not temp.get('locationInfo', None):
365365
return
366-
if not temp or not [x for x in (temp.location_info or []) if x.zones]:
366+
if not temp or not [x for x in temp.get('locationInfo', []) if x.get('zones', None)]:
367367
raise CLIError("{}'s location can't be used to create the VM/VMSS because availability zone is not yet "
368368
"supported. Please use '--location' to specify a capable one. 'az vm list-skus' can be "
369369
"used to find such locations".format(namespace.resource_group_name))

src/azure-cli/azure/cli/command_modules/vm/_vm_utils.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,18 @@ def get_key_vault_base_url(cli_ctx, vault_name):
118118

119119

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

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

126-
client = _compute_client_factory(cli_ctx)
127-
result = client.resource_skus.list()
126+
result = _ListSkus(cli_ctx=cli_ctx)(command_args={})
128127
if location:
129-
result = [r for r in result if _match_location(location, r.locations)]
128+
result = [r for r in result if _match_location(location, r['locations'])]
130129
return result
131130

132131

132+
# pylint: disable=line-too-long
133133
def is_sku_available(cmd, sku_info, zone):
134134
"""
135135
The SKU is unavailable in the following cases:
@@ -140,19 +140,19 @@ def is_sku_available(cmd, sku_info, zone):
140140
is_available = True
141141
is_restrict_zone = False
142142
is_restrict_location = False
143-
if not sku_info.restrictions:
143+
if not sku_info.get('restrictions', []):
144144
return is_available
145-
for restriction in sku_info.restrictions:
146-
if restriction.reason_code == 'NotAvailableForSubscription':
145+
for restriction in sku_info['restrictions']:
146+
if restriction.get('reason_code', '') == 'NotAvailableForSubscription':
147147
# The attribute location_info is not supported in versions 2017-03-30 and earlier
148148
if cmd.supported_api_version(max_api='2017-03-30'):
149149
is_available = False
150150
break
151-
if restriction.type == 'Zone' and not (
152-
set(sku_info.location_info[0].zones or []) - set(restriction.restriction_info.zones or [])):
151+
if restriction['type'] == 'Zone' and not (
152+
set(sku_info['location_info'][0].get('zones', [])) - set(restriction['restriction_info'].get('zones', []))):
153153
is_restrict_zone = True
154-
if restriction.type == 'Location' and (
155-
sku_info.location_info[0].location in (restriction.restriction_info.locations or [])):
154+
if restriction['type'] == 'Location' and (
155+
sku_info['location_info'][0]['location'] in (restriction['restriction_info'].get('locations', []))):
156156
is_restrict_location = True
157157

158158
if is_restrict_location or (is_restrict_zone and zone):

src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from ._deallocate import *
1515
from ._generalize import *
1616
from ._list_sizes import *
17+
from ._list_skus import *
1718
from ._list_vm_resize_options import *
1819
from ._perform_maintenance import *
1920
from ._reapply import *

0 commit comments

Comments
 (0)