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

[AppService] az functionapp create: Create consumption plan before creating function app #27812

Closed
wants to merge 1 commit into from
Closed
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
32 changes: 32 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 @@ -14,6 +14,7 @@

from binascii import hexlify
from os import urandom
from random import randint
import datetime
import json
import ssl
Expand Down Expand Up @@ -3728,6 +3729,27 @@ def create_functionapp_app_service_plan(cmd, resource_group_name, name, is_linux
return client.app_service_plans.begin_create_or_update(resource_group_name, name, plan_def)


def _generate_guid():
import random
import string
return ''.join(random.choices(string.ascii_lowercase + string.digits, k=4))


def create_consumption_plan(cmd, resource_group_name, name, is_linux, location):
SkuDescription, AppServicePlan = cmd.get_models('SkuDescription', 'AppServicePlan')
client = web_client_factory(cmd.cli_ctx)
sku_def = SkuDescription(tier='Dynamic', name='Y1', size='Y1', family='Y')
plan_def = AppServicePlan(
location=location,
sku=sku_def,
reserved=is_linux,
kind='functionapp',
name=name
)
poller = client.app_service_plans.begin_create_or_update(resource_group_name, name, plan_def)
return LongRunningOperation(cmd.cli_ctx)(poller)


def is_plan_consumption(cmd, plan_info):
SkuDescription, AppServicePlan = cmd.get_models('SkuDescription', 'AppServicePlan')
if isinstance(plan_info, AppServicePlan):
Expand Down Expand Up @@ -4016,6 +4038,16 @@ def create_functionapp(cmd, resource_group_name, name, storage_account, plan=Non
elif not disable_app_insights and matched_runtime.app_insights:
create_app_insights = True

# Create consumption plan
if consumption_plan_location is not None:
consumption_plan_name = 'ASP-{}-{}'.format(resource_group_name[:31], _generate_guid())
create_consumption_plan(cmd,
resource_group_name,
consumption_plan_name,
is_linux,
consumption_plan_location)
functionapp_def.server_farm_id = consumption_plan_name

poller = client.web_apps.begin_create_or_update(resource_group_name, name, functionapp_def)
functionapp = LongRunningOperation(cmd.cli_ctx)(poller)

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading