Skip to content

Commit 0550ae6

Browse files
committed
flex plan update zone redundant
1 parent 478da82 commit 0550ae6

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3231,6 +3231,9 @@ def update_functionapp_app_service_plan(cmd, instance, sku=None, number_of_worke
32313231
if number_of_workers is not None:
32323232
number_of_workers = validate_range_of_int_flag('--number-of-workers / --min-instances',
32333233
number_of_workers, min_val=0, max_val=20)
3234+
if is_plan_flex(cmd, instance):
3235+
return update_flex_app_service_plan(instance)
3236+
32343237
return update_app_service_plan(cmd, instance, sku, number_of_workers)
32353238

32363239

@@ -4982,6 +4985,19 @@ def create_flex_app_service_plan(cmd, resource_group_name, name, location, zone_
49824985
poller = client.app_service_plans.begin_create_or_update(resource_group_name, name, plan_def)
49834986
return LongRunningOperation(cmd.cli_ctx)(poller)
49844987

4988+
def update_flex_app_service_plan(instance):
4989+
instance.target_worker_count=None
4990+
instance.target_worker_size=None
4991+
instance.is_xenon=None
4992+
instance.hyper_v=None
4993+
instance.per_site_scaling=None
4994+
instance.maximum_elastic_worker_count=None
4995+
instance.elastic_scale_enabled=None
4996+
instance.is_spot=None
4997+
instance.target_worker_size_id=None
4998+
instance.sku.capacity=None
4999+
return instance
5000+
49855001

49865002
def create_functionapp_app_service_plan(cmd, resource_group_name, name, is_linux, sku, number_of_workers=None,
49875003
max_burst=None, location=None, tags=None, zone_redundant=False):
@@ -5012,6 +5028,13 @@ def is_plan_consumption(cmd, plan_info):
50125028
return plan_info.sku.tier.lower() == 'dynamic'
50135029
return False
50145030

5031+
def is_plan_flex(cmd, plan_info):
5032+
SkuDescription, AppServicePlan = cmd.get_models('SkuDescription', 'AppServicePlan')
5033+
if isinstance(plan_info, AppServicePlan):
5034+
if isinstance(plan_info.sku, SkuDescription):
5035+
return plan_info.sku.tier.lower() == 'flexconsumption'
5036+
return False
5037+
50155038

50165039
def is_plan_elastic_premium(cmd, plan_info):
50175040
SkuDescription, AppServicePlan = cmd.get_models('SkuDescription', 'AppServicePlan')

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,10 +853,44 @@ def test_functionapp_flex_zone_redundant_not_active(self, resource_group, storag
853853
.format(resource_group, functionapp_name, FLEX_ASP_LOCATION_FUNCTIONAPP, storage_account)).get_output_in_json()
854854

855855
server_farm_id =functionapp['properties']['serverFarmId']
856-
function_plan = self.cmd('az functionapp plan show --ids {}'
856+
function_plan = self.cmd('functionapp plan show --ids {}'
857857
.format(server_farm_id)).get_output_in_json()
858858
self.assertTrue(function_plan['zoneRedundant'] == False)
859859

860+
@ResourceGroupPreparer(location=FLEX_ASP_LOCATION_FUNCTIONAPP)
861+
@StorageAccountPreparer()
862+
def test_functionapp_flex_plan_enable_zone_redundant(self, resource_group, storage_account):
863+
functionapp_name = self.create_random_name(
864+
'functionapp', 40)
865+
866+
functionapp = self.cmd('functionapp create -g {} -n {} -f {} -s {} --runtime python --runtime-version 3.11'
867+
.format(resource_group, functionapp_name, FLEX_ASP_LOCATION_FUNCTIONAPP, storage_account)).get_output_in_json()
868+
869+
server_farm_id = functionapp['properties']['serverFarmId']
870+
function_plan = self.cmd('functionapp plan show --ids {}'.format(server_farm_id)).get_output_in_json()
871+
self.assertTrue(function_plan['zoneRedundant'] == False)
872+
updated_plan = self.cmd('functionapp plan update --id {} --set zoneRedundant=true'.format(server_farm_id)).get_output_in_json()
873+
self.assertTrue(updated_plan['zoneRedundant'] == True)
874+
function_plan = self.cmd('functionapp plan show --ids {}'.format(server_farm_id)).get_output_in_json()
875+
self.assertTrue(function_plan['zoneRedundant'] == True)
876+
877+
@ResourceGroupPreparer(location=FLEX_ASP_LOCATION_FUNCTIONAPP)
878+
@StorageAccountPreparer()
879+
def test_functionapp_flex_plan_disable_zone_redundant(self, resource_group, storage_account):
880+
functionapp_name = self.create_random_name(
881+
'functionapp', 40)
882+
883+
functionapp = self.cmd('functionapp create -g {} -n {} -f {} -s {} --runtime python --runtime-version 3.11 --zone-redundant'
884+
.format(resource_group, functionapp_name, FLEX_ASP_LOCATION_FUNCTIONAPP, storage_account)).get_output_in_json()
885+
886+
server_farm_id = functionapp['properties']['serverFarmId']
887+
function_plan = self.cmd('functionapp plan show --ids {}'.format(server_farm_id)).get_output_in_json()
888+
self.assertTrue(function_plan['zoneRedundant'] == True)
889+
updated_plan = self.cmd('functionapp plan update --id {} --set zoneRedundant=false'.format(server_farm_id)).get_output_in_json()
890+
self.assertTrue(updated_plan['zoneRedundant'] == False)
891+
function_plan = self.cmd('functionapp plan show --ids {}'.format(server_farm_id)).get_output_in_json()
892+
self.assertTrue(function_plan['zoneRedundant'] == False)
893+
860894
@ResourceGroupPreparer(location=FLEX_ASP_LOCATION_FUNCTIONAPP)
861895
@StorageAccountPreparer()
862896
def test_functionapp_flex_scale_config(self, resource_group, storage_account):

0 commit comments

Comments
 (0)