Skip to content

Commit b480a91

Browse files
committed
Check if flex region is enabled for subscription
1 parent 7cddb0b commit b480a91

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5721,6 +5721,13 @@ def list_consumption_locations(cmd):
57215721
return [{'name': x.name.lower().replace(' ', '')} for x in regions]
57225722

57235723

5724+
def get_subscription_locations(cli_ctx):
5725+
from azure.cli.core.commands.client_factory import get_subscription_service_client
5726+
subscription_client, subscription_id = get_subscription_service_client(cli_ctx)
5727+
result = list(subscription_client.subscriptions.list_locations(subscription_id))
5728+
return [item.name for item in result]
5729+
5730+
57245731
def list_flexconsumption_locations(cmd, zone_redundant=False):
57255732
if zone_redundant:
57265733
return list_flexconsumption_zone_redundant_locations(cmd)
@@ -5729,8 +5736,10 @@ def list_flexconsumption_locations(cmd, zone_redundant=False):
57295736
sub_id = get_subscription_id(cmd.cli_ctx)
57305737
geo_regions_api = 'subscriptions/{}/providers/Microsoft.Web/geoRegions?sku=FlexConsumption&api-version=2023-01-01'
57315738
request_url = cmd.cli_ctx.cloud.endpoints.resource_manager + geo_regions_api.format(sub_id)
5732-
regions = send_raw_request(cmd.cli_ctx, "GET", request_url).json()['value']
5733-
return [{'name': x['name'].lower().replace(' ', '')} for x in regions]
5739+
flex_regions = send_raw_request(cmd.cli_ctx, "GET", request_url).json()['value']
5740+
flex_regions_list = [{'name': x['name'].lower().replace(' ', '')} for x in flex_regions]
5741+
sub_regions_list = get_subscription_locations(cmd.cli_ctx)
5742+
return [x for x in flex_regions_list if x['name'] in sub_regions_list]
57345743

57355744

57365745
def list_locations(cmd, sku, linux_workers_enabled=None, hyperv_workers_enabled=None):

src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_functionapp_commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ def test_functionapp_update_enabled_dapr(self, resource_group, storage_account):
787787
class FunctionAppFlex(LiveScenarioTest):
788788
def test_functionapp_list_flexconsumption_locations(self):
789789
locations = self.cmd('functionapp list-flexconsumption-locations').get_output_in_json()
790-
self.assertTrue(len(locations) == 13)
790+
self.assertTrue(len(locations) == 12)
791791

792792
def test_functionapp_list_flexconsumption_locations_zone_redundant(self):
793793
locations = self.cmd('functionapp list-flexconsumption-locations --zone-redundant').get_output_in_json()

0 commit comments

Comments
 (0)