Skip to content

Commit 0eae60d

Browse files
committed
Add new arguments to create and update subcommands
1 parent 053ae57 commit 0eae60d

4 files changed

Lines changed: 529 additions & 2 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,20 @@ def load_arguments(self, _):
161161
c.argument('storage', help='The storage accounts for this resource, in JSON array format.')
162162
c.argument('encryption', help='The encryption properties for this resource, in JSON format.')
163163

164+
with self.argument_context('cognitiveservices account', arg_group="AI Services") as c:
165+
c.argument('allow_project_management',
166+
arg_type=get_three_state_flag(),
167+
help='Only used for AIServices kind. Specifies whether this resource support project management. Default is true.')
168+
164169
with self.argument_context('cognitiveservices account create') as c:
165170
c.argument('assign_identity', help='Generate and assign an Azure Active Directory Identity for this account.')
166171
c.argument('yes', action='store_true', help='Do not prompt for terms confirmation')
167172

173+
with self.argument_context('cognitiveservices account update', arg_group="AI Services") as c:
174+
c.argument('kind',
175+
arg_type=get_enum_type(data=['AIServices', 'OpenAI']),
176+
help='The target API name to transform the existing account into. See https://aka.ms/upgrade-aoai-foundry for details.')
177+
168178
with self.argument_context('cognitiveservices account network-rule') as c:
169179
c.argument('ip_address', help='IPv4 address or CIDR range.')
170180
c.argument('subnet', help='Name or ID of subnet. If name is supplied, `--vnet-name` must be supplied.')

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
Deployment, DeploymentModel, DeploymentScaleSettings, DeploymentProperties, \
1616
CommitmentPlan, CommitmentPlanProperties, CommitmentPeriod
1717
from azure.cli.command_modules.cognitiveservices._client_factory import cf_accounts, cf_resource_skus
18+
from azure.cli.core.azclierror import BadRequestError
1819

1920
logger = 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

8999
def 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

119134
def 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

Comments
 (0)