Skip to content

Commit 226c4a0

Browse files
committed
added details and runtime parameter to list-flexconsumption-locations command
1 parent 95ef126 commit 226c4a0

File tree

2 files changed

+43
-25
lines changed

2 files changed

+43
-25
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ def load_arguments(self, _):
232232
with self.argument_context('functionapp list-flexconsumption-locations') as c:
233233
c.argument('zone_redundant', arg_type=get_three_state_flag(),
234234
help='Filter the list to return only locations which support zone redundancy.', is_preview=True)
235+
c.argument('details', arg_type=get_three_state_flag(),
236+
help='Include the runtime details of the regions.', is_preview=True)
237+
c.argument('runtime', help="limit the output to just the specified runtime", is_preview=True)
235238

236239
with self.argument_context('webapp deleted list') as c:
237240
c.argument('name', arg_type=webapp_name_arg_type, id_part=None)

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

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,13 +1810,19 @@ def list_function_app_runtimes(cmd, os_type=None):
18101810
return {WINDOWS_OS_NAME: windows_stacks, LINUX_OS_NAME: linux_stacks}
18111811

18121812

1813-
def list_flex_function_app_runtimes(cmd, location, runtime):
1814-
runtime_helper = _FlexFunctionAppStackRuntimeHelper(cmd, location, runtime)
1815-
runtimes = [r for r in runtime_helper.stacks if runtime == r.name]
1816-
if not runtimes:
1817-
raise ValidationError("Runtime '{}' not supported for function apps on the Flex Consumption plan."
1818-
.format(runtime))
1819-
return runtimes
1813+
def list_flex_function_app_runtimes(cmd, location, runtime, ignore_error=False):
1814+
try:
1815+
runtime_helper = _FlexFunctionAppStackRuntimeHelper(cmd, location, runtime)
1816+
runtimes = [r for r in runtime_helper.stacks if runtime == r.name]
1817+
if not runtimes:
1818+
raise ValidationError("Runtime '{}' not supported for function apps on the Flex Consumption plan."
1819+
.format(runtime))
1820+
return runtime_helper.stacks
1821+
except Exception as e:
1822+
if ignore_error:
1823+
return []
1824+
else:
1825+
raise # Rethrow the caught exception
18201826

18211827

18221828
def delete_logic_app(cmd, resource_group_name, name, slot=None):
@@ -4576,7 +4582,7 @@ def stacks(self):
45764582

45774583
def get_flex_raw_function_app_stacks(self, cmd, location, runtime):
45784584
stacks_api_url = '/providers/Microsoft.Web/locations/{}/functionAppStacks?' \
4579-
'api-version=2020-10-01&removeHiddenStacks=true&removeDeprecatedStacks=true&stack={}'
4585+
'api-version=2023-12-01&removeHiddenStacks=true&removeDeprecatedStacks=true&stack={}'
45804586
if runtime == "dotnet-isolated":
45814587
runtime = "dotnet"
45824588
request_url = cmd.cli_ctx.cloud.endpoints.resource_manager + stacks_api_url.format(location, runtime)
@@ -5125,13 +5131,6 @@ def is_exactly_one_true(*args):
51255131
return found
51265132

51275133

5128-
def list_flexconsumption_zone_redundant_locations(cmd):
5129-
client = web_client_factory(cmd.cli_ctx)
5130-
regions = client.list_geo_regions(sku="FlexConsumption")
5131-
regions = [x for x in regions if "FCZONEREDUNDANCY" in x.org_domain]
5132-
return [{'name': x.name.lower().replace(' ', '')} for x in regions]
5133-
5134-
51355134
def create_functionapp(cmd, resource_group_name, name, storage_account, plan=None,
51365135
os_type=None, functions_version=None, runtime=None, runtime_version=None,
51375136
consumption_plan_location=None, app_insights=None, app_insights_key=None,
@@ -6132,19 +6131,35 @@ def get_subscription_locations(cli_ctx):
61326131
return [item.name for item in result]
61336132

61346133

6135-
def list_flexconsumption_locations(cmd, zone_redundant=False):
6134+
def list_flexconsumption_locations(cmd, zone_redundant=False, details=False, runtime=None):
6135+
client = web_client_factory(cmd.cli_ctx)
6136+
6137+
if runtime and not details:
6138+
raise ArgumentUsageError(
6139+
'--runtime is only valid with --details parameter. '
6140+
'Please try again without the --details parameter.')
6141+
6142+
regions = client.list_geo_regions(sku="FlexConsumption")
6143+
61366144
if zone_redundant:
6137-
return list_flexconsumption_zone_redundant_locations(cmd)
6145+
regions = [x for x in regions if "FCZONEREDUNDANCY" in x.org_domain]
61386146

6139-
from azure.cli.core.commands.client_factory import get_subscription_id
6140-
sub_id = get_subscription_id(cmd.cli_ctx)
6141-
geo_regions_api = 'subscriptions/{}/providers/Microsoft.Web/geoRegions?sku=FlexConsumption&api-version=2023-01-01'
6142-
request_url = cmd.cli_ctx.cloud.endpoints.resource_manager + geo_regions_api.format(sub_id)
6143-
flex_regions = send_raw_request(cmd.cli_ctx, "GET", request_url).json()['value']
6144-
flex_regions_list = [{'name': x['name'].lower().replace(' ', '')} for x in flex_regions]
6145-
sub_regions_list = get_subscription_locations(cmd.cli_ctx)
6146-
return [x for x in flex_regions_list if x['name'] in sub_regions_list]
6147+
regions = [x.name.lower().replace(' ', '') for x in regions]
6148+
return [{x: list_flex_function_app_all_runtimes(cmd, x, "java")} for x in regions]
6149+
6150+
6151+
def list_flex_function_app_all_runtimes(cmd, location, runtime=None):
6152+
runtimes = ["dotnet-isolated", "node", "python", "java", "powershell"]
6153+
if runtime:
6154+
runtimes = [runtime]
6155+
6156+
return [{x: list_flex_function_app_runtimes(cmd, location, x, True)} for x in runtimes]
61476157

6158+
def list_flexconsumption_zone_redundant_locations(cmd):
6159+
client = web_client_factory(cmd.cli_ctx)
6160+
regions = client.list_geo_regions(sku="FlexConsumption")
6161+
regions = [x for x in regions if "FCZONEREDUNDANCY" in x.org_domain]
6162+
return [{'name': x.name.lower().replace(' ', '')} for x in regions]
61486163

61496164
def list_locations(cmd, sku, linux_workers_enabled=None, hyperv_workers_enabled=None):
61506165
web_client = web_client_factory(cmd.cli_ctx)

0 commit comments

Comments
 (0)