Skip to content

Commit 819bf2d

Browse files
committed
Stack API to take SKU. Also made the class as generic
1 parent e40d423 commit 819bf2d

File tree

1 file changed

+18
-19
lines changed
  • src/azure-cli/azure/cli/command_modules/appservice

1 file changed

+18
-19
lines changed

src/azure-cli/azure/cli/command_modules/appservice/custom.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ def check_language_runtime(cmd, resource_group_name, name):
500500
runtime_helper.resolve(runtime, runtime_version, functions_version, is_linux)
501501
else:
502502
location = app.location
503-
runtime_helper = _FlexFunctionAppStackRuntimeHelper(cmd, location, runtime, runtime_version)
503+
runtime_helper = _FunctionAppSkuStackRuntimeHelper(cmd, location, runtime, "FC1", runtime_version)
504504
runtime_helper.resolve(runtime, runtime_version)
505505
except ValidationError as e:
506506
logger.warning(e.error_msg)
@@ -1057,7 +1057,7 @@ def validate_flex_migration_eligibility_for_linux_consumption_app(cmd, site, fle
10571057
runtime = runtime_info['app_runtime']
10581058
runtime_version = runtime_info['app_runtime_version']
10591059

1060-
runtime_helper = _FlexFunctionAppStackRuntimeHelper(cmd, normalized_site_location, runtime)
1060+
runtime_helper = _FunctionAppSkuStackRuntimeHelper(cmd, normalized_site_location, runtime, "FC1")
10611061
runtime_helper.resolve(runtime, runtime_version)
10621062

10631063
# Validating that the site does not have SSL bindings configured
@@ -2700,7 +2700,7 @@ def list_function_app_runtimes(cmd, os_type=None):
27002700

27012701

27022702
def list_flex_function_app_runtimes(cmd, location, runtime):
2703-
runtime_helper = _FlexFunctionAppStackRuntimeHelper(cmd, location, runtime)
2703+
runtime_helper = _FunctionAppSkuStackRuntimeHelper(cmd, location, runtime, "FC1")
27042704
runtimes = [r for r in runtime_helper.stacks if runtime == r.name]
27052705
if not runtimes:
27062706
raise ValidationError("Runtime '{}' not supported for function apps on the Flex Consumption plan."
@@ -3220,7 +3220,7 @@ def update_runtime_config(cmd, resource_group_name, name, runtime_version):
32203220
runtime = runtime_info['app_runtime']
32213221

32223222
location = functionapp["location"]
3223-
runtime_helper = _FlexFunctionAppStackRuntimeHelper(cmd, location, runtime, runtime_version)
3223+
runtime_helper = _FunctionAppSkuStackRuntimeHelper(cmd, location, runtime, "FC1", runtime_version)
32243224
matched_runtime = runtime_helper.resolve(runtime, runtime_version)
32253225
flex_sku = matched_runtime.sku
32263226
version = flex_sku['functionAppConfigProperties']['runtime']['version']
@@ -5592,7 +5592,7 @@ def _load_stacks_hardcoded(self):
55925592
self._stacks = stacks
55935593

55945594

5595-
class _FlexFunctionAppStackRuntimeHelper:
5595+
class _FunctionAppSkuStackRuntimeHelper:
55965596
class Runtime:
55975597
def __init__(self, name, version, app_insights=False, default=False, sku=None,
55985598
end_of_life_date=None, github_actions_properties=None):
@@ -5609,10 +5609,11 @@ def __init__(self, is_supported, supported_version):
56095609
self.is_supported = is_supported
56105610
self.supported_version = supported_version
56115611

5612-
def __init__(self, cmd, location, runtime, runtime_version=None):
5612+
def __init__(self, cmd, location, runtime, sku, runtime_version=None):
56135613
self._cmd = cmd
56145614
self._location = location
56155615
self._runtime = runtime
5616+
self._sku = sku
56165617
self._runtime_version = runtime_version
56175618
self._stacks = []
56185619

@@ -5621,12 +5622,12 @@ def stacks(self):
56215622
self._load_stacks()
56225623
return self._stacks
56235624

5624-
def get_flex_raw_function_app_stacks(self, cmd, location, runtime):
5625+
def get_raw_function_app_stacks(self, cmd, location, runtime, sku):
56255626
stacks_api_url = '/providers/Microsoft.Web/locations/{}/functionAppStacks?' \
5626-
'api-version=2020-10-01&removeHiddenStacks=true&removeDeprecatedStacks=true&stack={}'
5627+
'api-version=2020-10-01&removeHiddenStacks=true&removeDeprecatedStacks=true&stack={}?sku={}'
56275628
if runtime == "dotnet-isolated":
56285629
runtime = "dotnet"
5629-
request_url = cmd.cli_ctx.cloud.endpoints.resource_manager + stacks_api_url.format(location, runtime)
5630+
request_url = cmd.cli_ctx.cloud.endpoints.resource_manager + stacks_api_url.format(location, runtime, sku)
56305631
response = send_raw_request(cmd.cli_ctx, "GET", request_url)
56315632
return response.json()['value']
56325633

@@ -5666,8 +5667,6 @@ def _parse_raw_stacks(self, stacks):
56665667
continue
56675668

56685669
for sku in skus:
5669-
if sku['skuCode'] != 'FC1':
5670-
continue
56715670

56725671
github_actions_properties = {
56735672
'is_supported': github_actions_settings.get('isSupported', False),
@@ -5704,7 +5703,7 @@ def _create_runtime_from_properties(self, runtime_name, version_name, version_pr
57045703
def _load_stacks(self):
57055704
if self._stacks:
57065705
return
5707-
stacks = self.get_flex_raw_function_app_stacks(self._cmd, self._location, self._runtime)
5706+
stacks = self.get_raw_function_app_stacks(self._cmd, self._location, self._runtime, self._sku)
57085707
self._parse_raw_stacks(stacks)
57095708

57105709
def _get_version_variants(self, version):
@@ -5731,7 +5730,7 @@ def _find_matching_runtime_version(self, runtimes, version):
57315730
def resolve(self, runtime, version=None):
57325731
runtimes = [r for r in self.stacks if runtime == r.name]
57335732
if not runtimes:
5734-
raise ValidationError("Runtime '{}' not supported for function apps on the Flex Consumption plan."
5733+
raise ValidationError("Runtime '{}' not supported for function apps on this plan."
57355734
.format(runtime))
57365735
if version is None:
57375736
return self.get_default_version()
@@ -5743,8 +5742,7 @@ def resolve(self, runtime, version=None):
57435742

57445743
if not matched_runtime_version:
57455744
versions = [r.version for r in runtimes]
5746-
raise ValidationError("Invalid version {0} for runtime {1} for function apps on the Flex Consumption"
5747-
" plan. Supported versions for runtime {1} are {2}."
5745+
raise ValidationError("Invalid version {0} for runtime {1} for function apps on this plan. Supported versions for runtime {1} are {2}."
57485746
.format(version, runtime, versions))
57495747
return matched_runtime_version
57505748

@@ -5759,7 +5757,7 @@ class _FunctionAppStackRuntimeHelper(_AbstractStackRuntimeHelper):
57595757
class Runtime:
57605758
def __init__(self, name=None, version=None, is_preview=False, supported_func_versions=None, linux=False,
57615759
app_settings_dict=None, site_config_dict=None, app_insights=False, default=False,
5762-
github_actions_properties=None, end_of_life_date=None):
5760+
github_actions_properties=None, end_of_life_date=None, sku=None):
57635761
self.name = name
57645762
self.version = version
57655763
self.is_preview = is_preview
@@ -5771,6 +5769,7 @@ def __init__(self, name=None, version=None, is_preview=False, supported_func_ver
57715769
self.default = default
57725770
self.github_actions_properties = github_actions_properties
57735771
self.end_of_life_date = end_of_life_date
5772+
self.sku = sku
57745773

57755774
self.display_name = "{}|{}".format(name, version) if version else name
57765775
self.deprecation_link = LANGUAGE_EOL_DEPRECATION_NOTICES.get(self.display_name, '')
@@ -6429,7 +6428,7 @@ def create_functionapp(cmd, resource_group_name, name, storage_account, plan=Non
64296428
raise ArgumentUsageError('Must specify --runtime to use --runtime-version')
64306429

64316430
if flexconsumption_location:
6432-
runtime_helper = _FlexFunctionAppStackRuntimeHelper(cmd, flexconsumption_location, runtime, runtime_version)
6431+
runtime_helper = _FunctionAppSkuStackRuntimeHelper(cmd, flexconsumption_location, runtime, "FC1", runtime_version)
64336432
matched_runtime = runtime_helper.resolve(runtime, runtime_version)
64346433
else:
64356434
runtime_helper = _FunctionAppStackRuntimeHelper(cmd, linux=is_linux, windows=not is_linux)
@@ -7258,7 +7257,7 @@ def list_flex_function_app_all_runtimes(cmd, location, runtime=None):
72587257

72597258
def get_runtime_details_ignore_error(cmd, location, runtime):
72607259
try:
7261-
runtime_helper = _FlexFunctionAppStackRuntimeHelper(cmd, location, runtime)
7260+
runtime_helper = _FunctionAppSkuStackRuntimeHelper(cmd, location, runtime, "FC1")
72627261
return runtime_helper.stacks
72637262
except Exception: # pylint: disable=broad-except
72647263
return None
@@ -9883,7 +9882,7 @@ def _get_functionapp_runtime_version(cmd, location, name, resource_group, runtim
98839882
helper = _FunctionAppStackRuntimeHelper(cmd, linux=is_linux, windows=not is_linux)
98849883
matched_runtime = helper.resolve(runtime_string, runtime_version, functionapp_version, is_linux)
98859884
else:
9886-
runtime_helper = _FlexFunctionAppStackRuntimeHelper(cmd, location, runtime_string, runtime_version)
9885+
runtime_helper = _FunctionAppSkuStackRuntimeHelper(cmd, location, runtime_string, "FC1", runtime_version)
98879886
matched_runtime = runtime_helper.resolve(runtime_string, runtime_version)
98889887
except ValidationError as e:
98899888
if "Invalid version" in e.error_msg:

0 commit comments

Comments
 (0)