Skip to content
Merged
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
25 changes: 25 additions & 0 deletions src/azure-cli/azure/cli/command_modules/appservice/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -3231,6 +3231,9 @@ def update_functionapp_app_service_plan(cmd, instance, sku=None, number_of_worke
if number_of_workers is not None:
number_of_workers = validate_range_of_int_flag('--number-of-workers / --min-instances',
number_of_workers, min_val=0, max_val=20)
if is_plan_flex(cmd, instance):
return update_flex_app_service_plan(instance)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The instance here is the requested ServerFarm information from the user right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is done in a separate method. Command ensures that this method get the fully populated object (logic is in command definition). The job of this method is just to modify the object.


return update_app_service_plan(cmd, instance, sku, number_of_workers)


Expand Down Expand Up @@ -5022,6 +5025,20 @@ def create_flex_app_service_plan(cmd, resource_group_name, name, location, zone_
return LongRunningOperation(cmd.cli_ctx)(poller)


def update_flex_app_service_plan(instance):
instance.target_worker_count = None
instance.target_worker_size = None
instance.is_xenon = None
instance.hyper_v = None
instance.per_site_scaling = None
instance.maximum_elastic_worker_count = None
instance.elastic_scale_enabled = None
instance.is_spot = None
instance.target_worker_size_id = None
instance.sku.capacity = None
return instance


def create_functionapp_app_service_plan(cmd, resource_group_name, name, is_linux, sku, number_of_workers=None,
max_burst=None, location=None, tags=None, zone_redundant=False):
SkuDescription, AppServicePlan = cmd.get_models('SkuDescription', 'AppServicePlan')
Expand Down Expand Up @@ -5052,6 +5069,14 @@ def is_plan_consumption(cmd, plan_info):
return False


def is_plan_flex(cmd, plan_info):
SkuDescription, AppServicePlan = cmd.get_models('SkuDescription', 'AppServicePlan')
if isinstance(plan_info, AppServicePlan):
if isinstance(plan_info.sku, SkuDescription):
return plan_info.sku.tier.lower() == 'flexconsumption'
return False


def is_plan_elastic_premium(cmd, plan_info):
SkuDescription, AppServicePlan = cmd.get_models('SkuDescription', 'AppServicePlan')
if isinstance(plan_info, AppServicePlan):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -853,10 +853,44 @@ def test_functionapp_flex_zone_redundant_not_active(self, resource_group, storag
.format(resource_group, functionapp_name, FLEX_ASP_LOCATION_FUNCTIONAPP, storage_account)).get_output_in_json()

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

@ResourceGroupPreparer(location=FLEX_ASP_LOCATION_FUNCTIONAPP)
@StorageAccountPreparer()
def test_functionapp_flex_plan_enable_zone_redundant(self, resource_group, storage_account):
functionapp_name = self.create_random_name(
'functionapp', 40)

functionapp = self.cmd('functionapp create -g {} -n {} -f {} -s {} --runtime python --runtime-version 3.11'
.format(resource_group, functionapp_name, FLEX_ASP_LOCATION_FUNCTIONAPP, storage_account)).get_output_in_json()

server_farm_id = functionapp['properties']['serverFarmId']
function_plan = self.cmd('functionapp plan show --ids {}'.format(server_farm_id)).get_output_in_json()
self.assertTrue(function_plan['zoneRedundant'] == False)
updated_plan = self.cmd('functionapp plan update --id {} --set zoneRedundant=true'.format(server_farm_id)).get_output_in_json()
self.assertTrue(updated_plan['zoneRedundant'] == True)
function_plan = self.cmd('functionapp plan show --ids {}'.format(server_farm_id)).get_output_in_json()
self.assertTrue(function_plan['zoneRedundant'] == True)

@ResourceGroupPreparer(location=FLEX_ASP_LOCATION_FUNCTIONAPP)
@StorageAccountPreparer()
def test_functionapp_flex_plan_disable_zone_redundant(self, resource_group, storage_account):
functionapp_name = self.create_random_name(
'functionapp', 40)

functionapp = self.cmd('functionapp create -g {} -n {} -f {} -s {} --runtime python --runtime-version 3.11 --zone-redundant'
.format(resource_group, functionapp_name, FLEX_ASP_LOCATION_FUNCTIONAPP, storage_account)).get_output_in_json()

server_farm_id = functionapp['properties']['serverFarmId']
function_plan = self.cmd('functionapp plan show --ids {}'.format(server_farm_id)).get_output_in_json()
self.assertTrue(function_plan['zoneRedundant'] == True)
updated_plan = self.cmd('functionapp plan update --id {} --set zoneRedundant=false'.format(server_farm_id)).get_output_in_json()
self.assertTrue(updated_plan['zoneRedundant'] == False)
function_plan = self.cmd('functionapp plan show --ids {}'.format(server_farm_id)).get_output_in_json()
self.assertTrue(function_plan['zoneRedundant'] == False)

@ResourceGroupPreparer(location=FLEX_ASP_LOCATION_FUNCTIONAPP)
@StorageAccountPreparer()
def test_functionapp_flex_scale_config(self, resource_group, storage_account):
Expand Down