55
66import ipaddress
77
8- from azure .cli .core .azclierror import (InvalidArgumentValueError , ArgumentUsageError , ValidationError ,
9- MutuallyExclusiveArgumentError )
8+
9+ from azure .cli .core .azclierror import (InvalidArgumentValueError , ArgumentUsageError , RequiredArgumentMissingError ,
10+ ResourceNotFoundError , ValidationError , MutuallyExclusiveArgumentError )
1011from azure .cli .core .commands .client_factory import get_mgmt_service_client , get_subscription_id
1112from azure .cli .core .profiles import ResourceType
1213from azure .cli .core .commands .validators import validate_tags
1314
1415from knack .log import get_logger
15- from knack .util import CLIError
1616from msrestazure .tools import is_valid_resource_id , parse_resource_id
1717
1818from ._appservice_utils import _generic_site_operation
1919from ._client_factory import web_client_factory
20- from .utils import _normalize_sku , get_sku_name , _normalize_location
20+ from .utils import _normalize_sku , get_sku_tier , _normalize_location
2121
2222logger = get_logger (__name__ )
2323
@@ -59,7 +59,8 @@ def validate_site_create(cmd, namespace):
5959 else :
6060 plan_info = client .app_service_plans .get (resource_group_name , plan )
6161 if not plan_info :
62- raise CLIError ("The plan '{}' doesn't exist in the resource group '{}'" .format (plan , resource_group_name ))
62+ raise ResourceNotFoundError ("The plan '{}' doesn't exist in the resource group '{}'" .format (
63+ plan , resource_group_name ))
6364 # verify that the name is available for create
6465 validation_payload = {
6566 "name" : namespace .name ,
@@ -71,7 +72,7 @@ def validate_site_create(cmd, namespace):
7172 }
7273 validation = client .validate (resource_group_name , validation_payload )
7374 if validation .status .lower () == "failure" and validation .error .code != 'SiteAlreadyExists' :
74- raise CLIError (validation .error .message )
75+ raise ValidationError (validation .error .message )
7576
7677
7778def validate_ase_create (cmd , namespace ):
@@ -81,11 +82,11 @@ def validate_ase_create(cmd, namespace):
8182 if isinstance (namespace .name , str ):
8283 name_validation = client .check_name_availability (namespace .name , resource_type )
8384 if not name_validation .name_available :
84- raise CLIError (name_validation .message )
85+ raise ValidationError (name_validation .message )
8586
8687
8788def _validate_asp_sku (sku , app_service_environment , zone_redundant ):
88- if zone_redundant and get_sku_name (sku .upper ()) not in ['PREMIUMV2' , 'PREMIUMV3' ]:
89+ if zone_redundant and get_sku_tier (sku .upper ()) not in ['PREMIUMV2' , 'PREMIUMV3' ]:
8990 raise ValidationError ("Zone redundancy cannot be enabled for sku {}" .format (sku ))
9091 # Isolated SKU is supported only for ASE
9192 if sku .upper () in ['I1' , 'I2' , 'I3' , 'I1V2' , 'I2V2' , 'I3V2' ]:
@@ -110,7 +111,7 @@ def validate_asp_create(namespace):
110111def validate_functionapp_asp_create (namespace ):
111112 validate_tags (namespace )
112113 sku = _normalize_sku (namespace .sku )
113- tier = get_sku_name (sku )
114+ tier = get_sku_tier (sku )
114115 _validate_asp_sku (sku = sku , app_service_environment = None , zone_redundant = namespace .zone_redundant )
115116 if namespace .max_burst is not None :
116117 if tier .lower () != "elasticpremium" :
@@ -131,7 +132,7 @@ def validate_app_or_slot_exists_in_rg(cmd, namespace):
131132 else :
132133 app = client .web_apps .get (resource_group_name , webapp , None , raw = True )
133134 if app .response .status_code != 200 :
134- raise CLIError (app .response .text )
135+ raise ResourceNotFoundError (app .response .text )
135136
136137
137138def validate_app_exists_in_rg (cmd , namespace ):
@@ -140,11 +141,11 @@ def validate_app_exists_in_rg(cmd, namespace):
140141 resource_group_name = namespace .resource_group_name
141142 app = client .web_apps .get (resource_group_name , webapp , None , raw = True )
142143 if app .response .status_code != 200 :
143- raise CLIError (app .response .text )
144+ raise ResourceNotFoundError (app .response .text )
144145
145146
146147def validate_add_vnet (cmd , namespace ):
147- from azure .core .exceptions import ResourceNotFoundError
148+ from azure .core .exceptions import ResourceNotFoundError as ResNotFoundError
148149
149150 resource_group_name = namespace .resource_group_name
150151 from azure .cli .command_modules .network ._client_factory import network_client_factory
@@ -172,7 +173,7 @@ def validate_add_vnet(cmd, namespace):
172173 try :
173174 vnet_loc = vnet_client .virtual_networks .get (resource_group_name = namespace .resource_group_name ,
174175 virtual_network_name = vnet_identifier ).location
175- except ResourceNotFoundError :
176+ except ResNotFoundError :
176177 vnets = vnet_client .virtual_networks .list_all ()
177178 vnet_loc = ''
178179 for v in vnets :
@@ -202,7 +203,7 @@ def validate_front_end_scale_factor(namespace):
202203 scale_error_text = "Frontend Scale Factor '{}' is invalid. Must be between {} and {}"
203204 scale_factor = namespace .front_end_scale_factor
204205 if scale_factor < min_scale_factor or scale_factor > max_scale_factor :
205- raise CLIError (scale_error_text .format (scale_factor , min_scale_factor , max_scale_factor ))
206+ raise ValidationError (scale_error_text .format (scale_factor , min_scale_factor , max_scale_factor ))
206207
207208
208209def validate_ip_address (cmd , namespace ):
@@ -215,13 +216,13 @@ def validate_ip_address(cmd, namespace):
215216
216217def validate_onedeploy_params (namespace ):
217218 if namespace .src_path and namespace .src_url :
218- raise CLIError ('Only one of --src-path and --src-url can be specified' )
219+ raise MutuallyExclusiveArgumentError ('Only one of --src-path and --src-url can be specified' )
219220
220221 if not namespace .src_path and not namespace .src_url :
221- raise CLIError ('Either of --src-path or --src-url must be specified' )
222+ raise RequiredArgumentMissingError ('Either of --src-path or --src-url must be specified' )
222223
223224 if namespace .src_url and not namespace .artifact_type :
224- raise CLIError ('Deployment type is mandatory when deploying from URLs. Use --type' )
225+ raise RequiredArgumentMissingError ('Deployment type is mandatory when deploying from URLs. Use --type' )
225226
226227
227228def _validate_ip_address_format (namespace ):
@@ -304,7 +305,7 @@ def _validate_service_tag_existence(cmd, namespace):
304305def validate_public_cloud (cmd ):
305306 from azure .cli .core .cloud import AZURE_PUBLIC_CLOUD
306307 if cmd .cli_ctx .cloud .name != AZURE_PUBLIC_CLOUD .name :
307- raise CLIError ('This command is not yet supported on soveriegn clouds.' )
308+ raise ValidationError ('This command is not yet supported on soveriegn clouds.' )
308309
309310
310311def validate_staticsite_sku (cmd , namespace ):
@@ -352,7 +353,7 @@ def validate_vnet_integration(cmd, namespace):
352353
353354 sku_name = plan_info .sku .name
354355 disallowed_skus = {'FREE' , 'SHARED' , 'BASIC' , 'ElasticPremium' , 'PremiumContainer' , 'Isolated' , 'IsolatedV2' }
355- if get_sku_name (sku_name ) in disallowed_skus :
356+ if get_sku_tier (sku_name ) in disallowed_skus :
356357 raise ArgumentUsageError ("App Service Plan has invalid sku for vnet integration: {}."
357358 "Plan sku cannot be one of: {}. "
358359 "Please run 'az appservice plan create -h' "
0 commit comments