Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,21 @@ def load_arguments(self, _):
c.argument('storage', help='The storage accounts for this resource, in JSON array format.')
c.argument('encryption', help='The encryption properties for this resource, in JSON format.')

with self.argument_context('cognitiveservices account', arg_group="AI Services") as c:
c.argument('allow_project_management',
options_list=['--manage-projects', '--allow-project-management'],
arg_type=get_three_state_flag(),
help='AIServices kind only. Enables project management. Default true.')

with self.argument_context('cognitiveservices account create') as c:
c.argument('assign_identity', help='Generate and assign an Azure Active Directory Identity for this account.')
c.argument('yes', action='store_true', help='Do not prompt for terms confirmation')

with self.argument_context('cognitiveservices account update', arg_group="AI Services") as c:
c.argument('kind',
arg_type=get_enum_type(data=['AIServices', 'OpenAI']),
help='The target API name to transform the existing account into.')

with self.argument_context('cognitiveservices account network-rule') as c:
c.argument('ip_address', help='IPv4 address or CIDR range.')
c.argument('subnet', help='Name or ID of subnet. If name is supplied, `--vnet-name` must be supplied.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
Deployment, DeploymentModel, DeploymentScaleSettings, DeploymentProperties, \
CommitmentPlan, CommitmentPlanProperties, CommitmentPeriod
from azure.cli.command_modules.cognitiveservices._client_factory import cf_accounts, cf_resource_skus
from azure.cli.core.azclierror import BadRequestError

logger = get_logger(__name__)

Expand Down Expand Up @@ -86,25 +87,42 @@ def _filter_sku(_sku):
return [x for x in cf_resource_skus(cmd.cli_ctx).list() if _filter_sku(x)]


def _is_valid_kind_change(current_kind, target_kind):
valid_upgrades = {
'AIServices': ['OpenAI'],
'OpenAI': ['AIServices']
}
return target_kind in valid_upgrades.get(current_kind, [])


def _kind_uses_project_management(kind):
return kind in ['AIServices']


def create(
client, resource_group_name, account_name, sku_name, kind, location, custom_domain=None,
tags=None, api_properties=None, assign_identity=False, storage=None, encryption=None,
allow_project_management=None,
yes=None): # pylint: disable=unused-argument
"""
Create an Azure Cognitive Services account.
"""

sku = Sku(name=sku_name)

if _kind_uses_project_management(kind) and allow_project_management is None:
allow_project_management = True

properties = CognitiveServicesAccountProperties()
if api_properties is not None:
api_properties = CognitiveServicesAccountApiProperties.deserialize(api_properties)
properties.api_properties = api_properties
if custom_domain:
properties.custom_sub_domain_name = custom_domain
properties.allow_project_management = allow_project_management
params = CognitiveServicesAccount(sku=sku, kind=kind, location=location,
properties=properties, tags=tags)
if assign_identity:
if assign_identity or allow_project_management:
params.identity = Identity(type=IdentityType.system_assigned)

if storage is not None:
Expand All @@ -117,10 +135,12 @@ def create(


def update(client, resource_group_name, account_name, sku_name=None, custom_domain=None,
tags=None, api_properties=None, storage=None, encryption=None):
tags=None, api_properties=None, storage=None, encryption=None,
allow_project_management=None, kind=None):
"""
Update an Azure Cognitive Services account.
"""
sa = None
if sku_name is None:
sa = client.get(resource_group_name, account_name)
sku_name = sa.sku.name
Expand All @@ -133,8 +153,20 @@ def update(client, resource_group_name, account_name, sku_name=None, custom_doma
properties.api_properties = api_properties
if custom_domain:
properties.custom_sub_domain_name = custom_domain
if allow_project_management is not None:
properties.allow_project_management = allow_project_management

params = CognitiveServicesAccount(sku=sku, properties=properties, tags=tags)

if kind is not None:
if sa is None:
sa = client.get(resource_group_name, account_name)
if kind != sa.kind and not _is_valid_kind_change(sa.kind, kind):
raise BadRequestError("Changing the account kind from '{}' to '{}' is not supported.".format(sa.kind, kind))
params.kind = kind
if _kind_uses_project_management(kind) and allow_project_management is None:
params.properties.allow_project_management = True

if storage is not None:
params.properties.user_owned_storage = json.loads(storage)

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.

Loading
Loading