Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{Cognitive Services} Adopt track2 SDK, azure-mgmt-cognitiveservices==12.0.0 #18354

Merged
merged 27 commits into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cf336ef
Merge pull request #3 from Azure/dev
BigCat20196 Mar 24, 2021
783635e
Merge pull request #4 from Azure/dev
BigCat20196 Apr 2, 2021
1e0ede2
Merge pull request #5 from Azure/dev
BigCat20196 Apr 8, 2021
2137f75
Update test link
BigCat20196 Apr 8, 2021
ebd32e1
Merge pull request #6 from Azure/dev
BigCat20196 Apr 9, 2021
169ceb5
Merge branch 'jf_fix13385_408' into dev
BigCat20196 Apr 9, 2021
01d4476
Merge branch 'dev' of https://github.com/Azure/azure-cli into dev
BigCat20196 Apr 9, 2021
28dc2cf
Merge branch 'dev' of https://github.com/Azure/azure-cli into dev
BigCat20196 Apr 12, 2021
580a718
Merge pull request #7 from Azure/dev
BigCat20196 Apr 14, 2021
343c993
Merge pull request #8 from Azure/dev
BigCat20196 Apr 19, 2021
66e59c6
Merge pull request #9 from Azure/dev
BigCat20196 Apr 25, 2021
001e6c9
Merge pull request #11 from Azure/dev
BigCat20196 Apr 27, 2021
54c00cc
Merge pull request #12 from Azure/dev
BigCat20196 May 7, 2021
d8996cb
Merge pull request #13 from Azure/dev
BigCat20196 May 13, 2021
bf80c36
Merge pull request #14 from Azure/dev
BigCat20196 May 26, 2021
f8a49ba
Merge pull request #15 from Azure/dev
BigCat20196 May 31, 2021
ad8d348
Merge pull request #16 from Azure/dev
BigCat20196 May 31, 2021
029458c
Merge pull request #17 from Azure/dev
BigCat20196 May 31, 2021
1aa9b6b
update requirements
BigCat20196 May 31, 2021
97698c0
Merge branch 'dev' of https://github.com/BigCat20196/azure-cli into c…
BigCat20196 May 31, 2021
8f9f154
Fix tests
BigCat20196 Jun 4, 2021
de98cb0
Update cognitiviceservices==12.0.0
BigCat20196 Jun 9, 2021
4ddb498
Fix identity
BigCat20196 Jun 9, 2021
81deece
Fix tests
BigCat20196 Jun 10, 2021
9df4b27
Fix tests(delete unnecessary import)
BigCat20196 Jun 11, 2021
de33bdb
Fix tests(sku)
BigCat20196 Jun 11, 2021
4b486db
Upload test_recordings
BigCat20196 Jun 15, 2021
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 @@ -15,8 +15,8 @@ def load_command_table(self, _):

with self.command_group('cognitiveservices account', mgmt_type) as g:
g.custom_command('create', 'create')
g.command('delete', 'delete')
g.show_command('show', 'get_properties')
g.command('delete', 'begin_delete')
g.show_command('show', 'get')
g.custom_command('update', 'update')
g.custom_command('list', 'list_resources')
g.custom_command('list-skus', 'list_skus')
Expand Down
62 changes: 31 additions & 31 deletions src/azure-cli/azure/cli/command_modules/cognitiveservices/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
from knack.util import CLIError
from knack.log import get_logger

from azure.mgmt.cognitiveservices.models import CognitiveServicesAccount, Sku,\
from azure.mgmt.cognitiveservices.models import Account, Sku,\
VirtualNetworkRule, IpRule, NetworkRuleSet, NetworkRuleAction,\
CognitiveServicesAccountProperties, CognitiveServicesAccountApiProperties,\
Identity, IdentityType
AccountProperties, ApiProperties,\
Identity, ResourceIdentityType
from azure.cli.command_modules.cognitiveservices._client_factory import cf_accounts, cf_resource_skus


Expand All @@ -29,7 +29,7 @@ def list_usages(client, resource_group_name, account_name):
"""
List usages for Azure Cognitive Services account.
"""
return client.get_usages(resource_group_name, account_name).value
return client.list_usages(resource_group_name, account_name).value


def list_kinds(client):
Expand Down Expand Up @@ -109,50 +109,50 @@ def create(

sku = Sku(name=sku_name)

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

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

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

return client.create(resource_group_name, account_name, params)
return client.begin_create(resource_group_name, account_name, params)


def update(client, resource_group_name, account_name, sku_name=None, custom_domain=None,
tags=None, api_properties=None, storage=None, encryption=None):

if sku_name is None:
sa = client.get_properties(resource_group_name, account_name)
sa = client.get(resource_group_name, account_name)
sku_name = sa.sku.name

sku = Sku(name=sku_name)

properties = CognitiveServicesAccountProperties()
properties = AccountProperties()
if api_properties is not None:
api_properties = CognitiveServicesAccountApiProperties.deserialize(api_properties)
api_properties = ApiProperties.deserialize(api_properties)
properties.api_properties = api_properties
if custom_domain:
properties.custom_sub_domain_name = custom_domain
params = CognitiveServicesAccount(sku=sku, properties=properties, tags=tags)
params = Account(sku=sku, properties=properties, tags=tags)

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

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

return client.update(resource_group_name, account_name, params)
return client.begin_update(resource_group_name, account_name, params)


def default_network_acls():
Expand All @@ -164,7 +164,7 @@ def default_network_acls():


def list_network_rules(client, resource_group_name, account_name):
sa = client.get_properties(resource_group_name, account_name)
sa = client.get(resource_group_name, account_name)
rules = sa.properties.network_acls
if rules is None:
rules = default_network_acls()
Expand All @@ -173,7 +173,7 @@ def list_network_rules(client, resource_group_name, account_name):

def add_network_rule(client, resource_group_name, account_name, subnet=None,
vnet_name=None, ip_address=None): # pylint: disable=unused-argument
sa = client.get_properties(resource_group_name, account_name)
sa = client.get(resource_group_name, account_name)
rules = sa.properties.network_acls
if rules is None:
rules = default_network_acls()
Expand All @@ -191,16 +191,16 @@ def add_network_rule(client, resource_group_name, account_name, subnet=None,
rules.ip_rules = []
rules.ip_rules.append(IpRule(value=ip_address))

properties = CognitiveServicesAccountProperties()
properties = AccountProperties()
properties.network_acls = rules
params = CognitiveServicesAccount(properties=properties)
params = Account(properties=properties)

return client.update(resource_group_name, account_name, params)
return client.begin_update(resource_group_name, account_name, params)


def remove_network_rule(client, resource_group_name, account_name, ip_address=None, subnet=None,
vnet_name=None): # pylint: disable=unused-argument
sa = client.get_properties(resource_group_name, account_name)
sa = client.get(resource_group_name, account_name)
rules = sa.properties.network_acls
if rules is None:
# nothing to update, but return the object
Expand All @@ -212,26 +212,26 @@ def remove_network_rule(client, resource_group_name, account_name, ip_address=No
if ip_address:
rules.ip_rules = [x for x in rules.ip_rules if x.value != ip_address]

properties = CognitiveServicesAccountProperties()
properties = AccountProperties()
properties.network_acls = rules
params = CognitiveServicesAccount(properties=properties)
params = Account(properties=properties)

return client.update(resource_group_name, account_name, params)
return client.begin_update(resource_group_name, account_name, params)


def identity_assign(client, resource_group_name, account_name):
params = CognitiveServicesAccount()
params.identity = Identity(type=IdentityType.system_assigned)
sa = client.update(resource_group_name, account_name, params)
params = Account()
params.identity = Identity(type=ResourceIdentityType.system_assigned)
sa = client.begin_update(resource_group_name, account_name, params).result()
return sa.identity if sa.identity else {}


def identity_remove(client, resource_group_name, account_name):
params = CognitiveServicesAccount()
params.identity = Identity(type=IdentityType.none)
client.update(resource_group_name, account_name, params)
params = Account()
params.identity = Identity(type=ResourceIdentityType.none)
client.begin_update(resource_group_name, account_name, params)


def identity_show(client, resource_group_name, account_name):
sa = client.get_properties(resource_group_name, account_name)
sa = client.get(resource_group_name, account_name)
return sa.identity if sa.identity else {}
Loading