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

[App Service] az functionapp list-flexconsumption-locations: Add --details and --runtime parameters to provide more details #31019

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ def load_arguments(self, _):
with self.argument_context('functionapp list-flexconsumption-locations') as c:
c.argument('zone_redundant', arg_type=get_three_state_flag(),
help='Filter the list to return only locations which support zone redundancy.', is_preview=True)
c.argument('details', arg_type=get_three_state_flag(),
help='Include the runtime details of the regions.', is_preview=True)
c.argument('runtime', help="limit the output to just the specified runtime", is_preview=True)

with self.argument_context('webapp deleted list') as c:
c.argument('name', arg_type=webapp_name_arg_type, id_part=None)
Expand Down
67 changes: 44 additions & 23 deletions src/azure-cli/azure/cli/command_modules/appservice/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1810,13 +1810,19 @@ def list_function_app_runtimes(cmd, os_type=None):
return {WINDOWS_OS_NAME: windows_stacks, LINUX_OS_NAME: linux_stacks}


def list_flex_function_app_runtimes(cmd, location, runtime):
runtime_helper = _FlexFunctionAppStackRuntimeHelper(cmd, location, runtime)
runtimes = [r for r in runtime_helper.stacks if runtime == r.name]
if not runtimes:
raise ValidationError("Runtime '{}' not supported for function apps on the Flex Consumption plan."
.format(runtime))
return runtimes
def list_flex_function_app_runtimes(cmd, location, runtime, ignore_error=False):
try:
runtime_helper = _FlexFunctionAppStackRuntimeHelper(cmd, location, runtime)
runtimes = [r for r in runtime_helper.stacks if runtime == r.name]
if not runtimes:
raise ValidationError("Runtime '{}' not supported for function apps on the Flex Consumption plan."
.format(runtime))
return runtime_helper.stacks
except Exception as e:
if ignore_error:
return []
else:
raise # Rethrow the caught exception


def delete_logic_app(cmd, resource_group_name, name, slot=None):
Expand Down Expand Up @@ -5125,13 +5131,6 @@ def is_exactly_one_true(*args):
return found


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


def create_functionapp(cmd, resource_group_name, name, storage_account, plan=None,
os_type=None, functions_version=None, runtime=None, runtime_version=None,
consumption_plan_location=None, app_insights=None, app_insights_key=None,
Expand Down Expand Up @@ -6132,19 +6131,41 @@ def get_subscription_locations(cli_ctx):
return [item.name for item in result]


def list_flexconsumption_locations(cmd, zone_redundant=False):
def list_flexconsumption_locations(cmd, zone_redundant=False, details=False, runtime=None):
client = web_client_factory(cmd.cli_ctx)

if runtime and not details:
raise ArgumentUsageError(
'--runtime is only valid with --details parameter. '
'Please try again without the --details parameter.')

regions = client.list_geo_regions(sku="FlexConsumption")

if zone_redundant:
return list_flexconsumption_zone_redundant_locations(cmd)
regions = [x for x in regions if "FCZONEREDUNDANCY" in x.org_domain]

from azure.cli.core.commands.client_factory import get_subscription_id
sub_id = get_subscription_id(cmd.cli_ctx)
geo_regions_api = 'subscriptions/{}/providers/Microsoft.Web/geoRegions?sku=FlexConsumption&api-version=2023-01-01'
request_url = cmd.cli_ctx.cloud.endpoints.resource_manager + geo_regions_api.format(sub_id)
flex_regions = send_raw_request(cmd.cli_ctx, "GET", request_url).json()['value']
flex_regions_list = [{'name': x['name'].lower().replace(' ', '')} for x in flex_regions]
regions = [x.name.lower().replace(' ', '') for x in regions]
sub_regions_list = get_subscription_locations(cmd.cli_ctx)
return [x for x in flex_regions_list if x['name'] in sub_regions_list]
regions = [x for x in regions if x in sub_regions_list]

if not details:
return [{'name': x} for x in regions]

return [{'name': x, 'details': list_flex_function_app_all_runtimes(cmd, x, runtime)} for x in regions]


def list_flex_function_app_all_runtimes(cmd, location, runtime=None):
runtimes = ["dotnet-isolated", "node", "python", "java", "powershell"]
if runtime:
runtimes = [runtime]

return [{'runtime': x, 'runtime-details': list_flex_function_app_runtimes(cmd, location, x, True)} for x in runtimes]

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

def list_locations(cmd, sku, linux_workers_enabled=None, hyperv_workers_enabled=None):
web_client = web_client_factory(cmd.cli_ctx)
Expand Down
Loading