Skip to content

Commit cb9164b

Browse files
committed
add logic for elastic-web-app-scale-limit and other param options
1 parent 8816586 commit cb9164b

6 files changed

+2588
-476
lines changed

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def load_arguments(self, _):
131131
with self.argument_context('appservice plan update') as c:
132132
c.argument('sku', arg_type=sku_arg_type)
133133
c.argument('elastic_scale', arg_type=get_three_state_flag(), is_preview=True, help='Enable or disable automatic scaling. Set to "true" to enable elastic scale for this plan, or "false" to disable elastic scale for this plan. The SKU must be a Premium V2 SKU (P1V2, P2V2, P3V2) or a Premium V3 SKU (P1V3, P2V3, P3V3)')
134-
c.argument('max_elastic_worker_count', options_list=['--max-elastic-worker-count', '-m'], type=int, is_preview=True, help='Maximum number of instances that the plan can scale out to. The plan must be an elastic scale plan.')
134+
c.argument('max_elastic_worker_count', options_list=['--max-elastic-worker-count', '--max-app-service-plan-instance-count', '-m'], type=int, is_preview=True, help='Maximum number of instances that the plan can scale out to. The plan must be an elastic scale plan.')
135135
c.argument('number_of_workers', type=int, help='Number of workers to be allocated.')
136136
c.ignore('allow_pending_state')
137137

@@ -207,8 +207,9 @@ def load_arguments(self, _):
207207
arg_type=get_three_state_flag(return_label=True), deprecate_info=c.deprecate(expiration='3.0.0'))
208208
c.argument('skip_dns_registration', help="If true web app hostname is not registered with DNS on creation",
209209
arg_type=get_three_state_flag(return_label=True), deprecate_info=c.deprecate(expiration='3.0.0'))
210-
c.argument('minimum_elastic_instance_count', options_list=["--minimum-elastic-instance-count", "-i"], type=int, is_preview=True, help="Minimum number of instances. App must be in an elastic scale App Service Plan.")
211-
c.argument('prewarmed_instance_count', options_list=["--prewarmed-instance-count", "-w"], type=int, is_preview=True, help="Number of preWarmed instances. App must be in an elastic scale App Service Plan.")
210+
c.argument('minimum_elastic_instance_count', options_list=['--minimum-elastic-instance-count', '--min-web-app-instance-count', '-i'], type=int, is_preview=True, help="Minimum number of instances. App must be in an elastic scale App Service Plan.")
211+
c.argument('elastic_web_app_scale_limit', options_list=['--elastic-web-app-scale-limit', '--max-web-app-instance-count', '-x'], type=int, is_preview=True, help="Maximum number of instances. App must be in an elastic scale App Service Plan.")
212+
c.argument('prewarmed_instance_count', options_list=['--prewarmed-instance-count', '-w'], type=int, is_preview=True, help="Number of preWarmed instances. App must be in an elastic scale App Service Plan.")
212213

213214
with self.argument_context('webapp browse') as c:
214215
c.argument('logs', options_list=['--logs', '-l'], action='store_true',

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

+21-5
Original file line numberDiff line numberDiff line change
@@ -853,25 +853,33 @@ def set_webapp(cmd, resource_group_name, name, slot=None, skip_dns_registration=
853853

854854

855855
def update_webapp(cmd, instance, client_affinity_enabled=None, https_only=None, minimum_elastic_instance_count=None,
856-
prewarmed_instance_count=None):
856+
elastic_web_app_scale_limit=None, prewarmed_instance_count=None):
857857
if 'function' in instance.kind:
858858
raise ValidationError("please use 'az functionapp update' to update this function app")
859-
if minimum_elastic_instance_count or prewarmed_instance_count:
860-
args = ["--minimum-elastic-instance-count", "--prewarmed-instance-count"]
859+
if minimum_elastic_instance_count or prewarmed_instance_count or elastic_web_app_scale_limit:
860+
args = ["--minimum-elastic-instance-count", "--prewarmed-instance-count", "--elastic-web-app-scale-limit"]
861861
plan = get_app_service_plan_from_webapp(cmd, instance)
862862
sku = _normalize_sku(plan.sku.name)
863863
if get_sku_tier(sku) not in ["PREMIUMV2", "PREMIUMV3"]:
864864
raise ValidationError("{} are only supported for elastic premium V2/V3 SKUs".format(str(args)))
865865
if not plan.elastic_scale_enabled:
866866
raise ValidationError("Elastic scale is not enabled on the App Service Plan. Please update the plan ")
867+
if ((elastic_web_app_scale_limit or 0) < 0) or \
868+
((minimum_elastic_instance_count or 0) < 0) or \
869+
((prewarmed_instance_count or 0) < 0):
870+
raise ValidationError("Value cannot be less than 0 for {}.".format(str(args)))
867871
if (minimum_elastic_instance_count or 0) > plan.maximum_elastic_worker_count:
868872
raise ValidationError("--minimum-elastic-instance-count: Minimum elastic instance count is greater than "
869873
"the app service plan's maximum Elastic worker count. "
870-
"Please choose a lower count or update the plan's maximum ")
874+
"Please choose a lower count or update the plan's maximum.")
871875
if (prewarmed_instance_count or 0) > plan.maximum_elastic_worker_count:
872876
raise ValidationError("--prewarmed-instance-count: Prewarmed instance count is greater than "
873877
"the app service plan's maximum Elastic worker count. "
874-
"Please choose a lower count or update the plan's maximum ")
878+
"Please choose a lower count or update the plan's maximum.")
879+
if (elastic_web_app_scale_limit or 0) > plan.maximum_elastic_worker_count:
880+
raise ValidationError("--elastic-web-app-scale-limit: Elastic web app scale limit is greater than "
881+
"the app service plan's maximum Elastic worker count. "
882+
"Please choose a lower count or update the plan's maximum.")
875883

876884
if client_affinity_enabled is not None:
877885
instance.client_affinity_enabled = client_affinity_enabled == 'true'
@@ -888,6 +896,14 @@ def update_webapp(cmd, instance, client_affinity_enabled=None, https_only=None,
888896
if prewarmed_instance_count is not None:
889897
instance.site_config.pre_warmed_instance_count = prewarmed_instance_count
890898

899+
if elastic_web_app_scale_limit is not None:
900+
instance.site_config.elastic_web_app_scale_limit = elastic_web_app_scale_limit
901+
minim = instance.site_config.minimum_elastic_instance_count
902+
if minim and (elastic_web_app_scale_limit < minim):
903+
raise ValidationError("--elastic-web-app-scale-limit: Elastic web app scale limit "
904+
"cannot be less than minimum elastic instance count. "
905+
"Please choose a higher count or update the minimum elastic instance count.")
906+
891907
return instance
892908

893909

0 commit comments

Comments
 (0)