1515 Deployment , DeploymentModel , DeploymentScaleSettings , DeploymentProperties , \
1616 CommitmentPlan , CommitmentPlanProperties , CommitmentPeriod
1717from azure .cli .command_modules .cognitiveservices ._client_factory import cf_accounts , cf_resource_skus
18+ from azure .cli .core .azclierror import BadRequestError
1819
1920logger = get_logger (__name__ )
2021
@@ -85,26 +86,40 @@ def _filter_sku(_sku):
8586
8687 return [x for x in cf_resource_skus (cmd .cli_ctx ).list () if _filter_sku (x )]
8788
89+ def _is_valid_kind_change (current_kind , target_kind ):
90+ valid_upgrades = {
91+ 'AIServices' : ['OpenAI' ],
92+ 'OpenAI' : ['AIServices' ]
93+ }
94+ return target_kind in valid_upgrades .get (current_kind , [])
95+
96+ def _kind_uses_project_management (kind ):
97+ return kind in ['AIServices' ]
8898
8999def create (
90100 client , resource_group_name , account_name , sku_name , kind , location , custom_domain = None ,
91101 tags = None , api_properties = None , assign_identity = False , storage = None , encryption = None ,
102+ allow_project_management = None ,
92103 yes = None ): # pylint: disable=unused-argument
93104 """
94105 Create an Azure Cognitive Services account.
95106 """
96107
97108 sku = Sku (name = sku_name )
98109
110+ if _kind_uses_project_management (kind ) and allow_project_management is None :
111+ allow_project_management = True
112+
99113 properties = CognitiveServicesAccountProperties ()
100114 if api_properties is not None :
101115 api_properties = CognitiveServicesAccountApiProperties .deserialize (api_properties )
102116 properties .api_properties = api_properties
103117 if custom_domain :
104118 properties .custom_sub_domain_name = custom_domain
119+ properties .allow_project_management = allow_project_management
105120 params = CognitiveServicesAccount (sku = sku , kind = kind , location = location ,
106121 properties = properties , tags = tags )
107- if assign_identity :
122+ if assign_identity or allow_project_management :
108123 params .identity = Identity (type = IdentityType .system_assigned )
109124
110125 if storage is not None :
@@ -117,10 +132,12 @@ def create(
117132
118133
119134def update (client , resource_group_name , account_name , sku_name = None , custom_domain = None ,
120- tags = None , api_properties = None , storage = None , encryption = None ):
135+ tags = None , api_properties = None , storage = None , encryption = None ,
136+ allow_project_management = None , kind = None ):
121137 """
122138 Update an Azure Cognitive Services account.
123139 """
140+ sa = None
124141 if sku_name is None :
125142 sa = client .get (resource_group_name , account_name )
126143 sku_name = sa .sku .name
@@ -133,8 +150,20 @@ def update(client, resource_group_name, account_name, sku_name=None, custom_doma
133150 properties .api_properties = api_properties
134151 if custom_domain :
135152 properties .custom_sub_domain_name = custom_domain
153+ if allow_project_management is not None :
154+ properties .allow_project_management = allow_project_management
155+
136156 params = CognitiveServicesAccount (sku = sku , properties = properties , tags = tags )
137157
158+ if kind is not None :
159+ if sa is None :
160+ sa = client .get (resource_group_name , account_name )
161+ if kind != sa .kind and not _is_valid_kind_change (sa .kind , kind ):
162+ raise BadRequestError ("Changing the account kind from '{}' to '{}' is not supported." .format (sa .kind , kind ))
163+ params .kind = kind
164+ if _kind_uses_project_management (kind ) and allow_project_management is None :
165+ params .properties .allow_project_management = True
166+
138167 if storage is not None :
139168 params .properties .user_owned_storage = json .loads (storage )
140169
0 commit comments