Skip to content

Commit 02bbf58

Browse files
authored
{App Service} az appservice plan create: Add default OS as Linux (#33395)
1 parent 5e912a2 commit 02bbf58

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ def load_arguments(self, _):
126126
subscription than the app service environment, please use the resource ID for --app-service-environment parameter. ",
127127
local_context_attribute=LocalContextAttribute(name='ase_name', actions=[LocalContextAction.GET]))
128128
c.argument('sku', arg_type=sku_arg_type)
129-
c.argument('is_linux', action='store_true', required=False, help='host web app on Linux worker')
129+
c.argument('is_linux', arg_type=get_three_state_flag(), default=None, required=False,
130+
help='Host web app on Linux worker. Defaults to true unless --hyper-v is specified. '
131+
'Use "--is-linux false" to create a Windows plan.')
130132
c.argument('hyper_v', action='store_true', required=False, help='Host Windows Container Web App on Hyper-V worker.')
131133
c.argument('per_site_scaling', action='store_true', required=False, help='Enable per-app scaling at the '
132134
'App Service plan level to allow for '

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ def _validate_asp_sku(sku, app_service_environment, zone_redundant):
111111

112112
def validate_asp_create(namespace):
113113
validate_tags(namespace)
114+
# is_linux is None when not explicitly provided by the user (default).
115+
# Resolve the default: Linux unless --hyper-v is specified.
116+
if namespace.is_linux is None:
117+
namespace.is_linux = not namespace.hyper_v
118+
elif namespace.is_linux and namespace.hyper_v:
119+
raise MutuallyExclusiveArgumentError('Usage error: --is-linux true and --hyper-v cannot be used together.')
114120
if namespace.sku is None:
115121
if namespace.is_linux:
116122
namespace.sku = 'P0V3'
@@ -122,8 +128,6 @@ def validate_asp_create(namespace):
122128
namespace.sku = 'B1'
123129
sku = _normalize_sku(namespace.sku)
124130
_validate_asp_sku(sku, namespace.app_service_environment, namespace.zone_redundant)
125-
if namespace.is_linux and namespace.hyper_v:
126-
raise MutuallyExclusiveArgumentError('Usage error: --is-linux and --hyper-v cannot be used together.')
127131

128132

129133
def validate_functionapp_asp_create(namespace):

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4979,12 +4979,18 @@ def is_async_response(poller, timeout_seconds=30):
49794979
return status_code == 202
49804980

49814981

4982-
def create_app_service_plan(cmd, resource_group_name, name, is_linux, hyper_v, per_site_scaling=False,
4982+
def create_app_service_plan(cmd, resource_group_name, name, is_linux, hyper_v, per_site_scaling=False, # pylint: disable=too-many-branches
49834983
app_service_environment=None, sku=None, number_of_workers=None, location=None,
49844984
tags=None, no_wait=False, zone_redundant=False, async_scaling_enabled=None,
49854985
is_managed_instance=None, mi_system_assigned=None, mi_user_assigned=None,
49864986
default_identity=None, rdp_enabled=None, vnet=None, subnet=None,
49874987
registry_adapters=None, install_scripts=None, storage_mounts=None):
4988+
if is_linux is None:
4989+
is_linux = not hyper_v
4990+
elif is_linux and hyper_v:
4991+
raise MutuallyExclusiveArgumentError('--hyper-v creates a Windows container plan and cannot be combined '
4992+
'with --is-linux true. Omit --is-linux or use "--is-linux false".')
4993+
49884994
if sku is None:
49894995
sku = 'P0V3' if is_linux else 'B1'
49904996

@@ -5073,6 +5079,9 @@ def pre_operations(self):
50735079
args = self.ctx.args
50745080
args.no_wait = no_wait
50755081

5082+
os_type = 'Linux' if is_linux else ('Hyper-V' if hyper_v else 'Windows')
5083+
logger.warning("Creating App Service Plan '%s' (%s, SKU: %s).", name, os_type, sku)
5084+
50765085
poller = AppServicePlanCreateWithNoWait(cli_ctx=cmd.cli_ctx)(command_args={
50775086
"name": name,
50785087
"resource_group": resource_group_name,
@@ -5098,9 +5107,6 @@ def pre_operations(self):
50985107
"storage_mounts": storage_mounts,
50995108
})
51005109

5101-
os_type = 'Linux' if is_linux else ('Hyper-V' if hyper_v else 'Windows')
5102-
logger.warning("Creating App Service Plan '%s' (%s).", name, os_type)
5103-
51045110
if no_wait:
51055111
return poller.result()
51065112

0 commit comments

Comments
 (0)