Skip to content

Commit d41f726

Browse files
authored
{Cognitive Services} Upgrade azure-mgmt-cognitiveservices to 15.0.0b1 and add managed-network commands (#33132)
1 parent a5aec14 commit d41f726

File tree

39 files changed

+1171
-206
lines changed

39 files changed

+1171
-206
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,18 @@ def cf_account_connections(cli_ctx, *_):
9393
return get_cognitiveservices_management_client(cli_ctx).account_connections
9494

9595

96+
def cf_managed_network_settings(cli_ctx, *_):
97+
return get_cognitiveservices_management_client(cli_ctx).managed_network_settings
98+
99+
100+
def cf_managed_network_provisions(cli_ctx, *_):
101+
return get_cognitiveservices_management_client(cli_ctx).managed_network_provisions
102+
103+
104+
def cf_outbound_rule(cli_ctx, *_):
105+
return get_cognitiveservices_management_client(cli_ctx).outbound_rule
106+
107+
96108
def cf_account_capability_hosts(cli_ctx, *_):
97109
return get_cognitiveservices_management_client(cli_ctx).account_capability_hosts
98110

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

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,166 @@
719719
text: az cognitiveservices agent update --account-name myAccount --project-name myProject --name myAgent --agent-version 1 --min-replicas 1 --max-replicas 2
720720
"""
721721

722+
helps['cognitiveservices account managed-network'] = """
723+
type: group
724+
short-summary: Manage the managed network settings for an Azure Cognitive Services account.
725+
long-summary: >
726+
Managed network settings control the network isolation mode and firewall configuration
727+
for AI Foundry accounts.
728+
"""
729+
730+
helps['cognitiveservices account managed-network create'] = """
731+
type: command
732+
short-summary: Create a managed network for an Azure Cognitive Services account.
733+
examples:
734+
- name: Create a managed network with internet outbound access.
735+
text: >
736+
az cognitiveservices account managed-network create
737+
--name my-account
738+
--resource-group my-resource-group
739+
--managed-network allow_internet_outbound
740+
- name: Create a managed network with approved outbound only and a standard firewall.
741+
text: >
742+
az cognitiveservices account managed-network create
743+
--name my-account
744+
--resource-group my-resource-group
745+
--managed-network allow_only_approved_outbound
746+
--firewall-sku Standard
747+
"""
748+
749+
helps['cognitiveservices account managed-network update'] = """
750+
type: command
751+
short-summary: Update managed network settings for an Azure Cognitive Services account.
752+
examples:
753+
- name: Update the firewall SKU.
754+
text: >
755+
az cognitiveservices account managed-network update
756+
--name my-account
757+
--resource-group my-resource-group
758+
--firewall-sku Standard
759+
- name: Change the isolation mode.
760+
text: >
761+
az cognitiveservices account managed-network update
762+
--name my-account
763+
--resource-group my-resource-group
764+
--managed-network allow_only_approved_outbound
765+
"""
766+
767+
helps['cognitiveservices account managed-network show'] = """
768+
type: command
769+
short-summary: Show the managed network settings for an Azure Cognitive Services account.
770+
examples:
771+
- name: Show managed network settings.
772+
text: >
773+
az cognitiveservices account managed-network show
774+
--name my-account
775+
--resource-group my-resource-group
776+
"""
777+
778+
helps['cognitiveservices account managed-network provision-network'] = """
779+
type: command
780+
short-summary: Provision the managed network for an Azure Cognitive Services account.
781+
long-summary: >
782+
Triggers provisioning of the managed network. This is a long-running operation.
783+
examples:
784+
- name: Provision the managed network.
785+
text: >
786+
az cognitiveservices account managed-network provision-network
787+
--name my-account
788+
--resource-group my-resource-group
789+
"""
790+
791+
helps['cognitiveservices account managed-network outbound-rule'] = """
792+
type: group
793+
short-summary: Manage outbound rules for the managed network of an Azure Cognitive Services account.
794+
long-summary: >
795+
Outbound rules control egress traffic from the managed network. Rules can be
796+
of type FQDN, PrivateEndpoint, or ServiceTag.
797+
"""
798+
799+
helps['cognitiveservices account managed-network outbound-rule list'] = """
800+
type: command
801+
short-summary: List all outbound rules for the managed network.
802+
examples:
803+
- name: List all outbound rules.
804+
text: >
805+
az cognitiveservices account managed-network outbound-rule list
806+
--name my-account
807+
--resource-group my-resource-group
808+
"""
809+
810+
helps['cognitiveservices account managed-network outbound-rule show'] = """
811+
type: command
812+
short-summary: Show details of an outbound rule.
813+
examples:
814+
- name: Show an outbound rule.
815+
text: >
816+
az cognitiveservices account managed-network outbound-rule show
817+
--name my-account
818+
--resource-group my-resource-group
819+
--rule my-rule
820+
"""
821+
822+
helps['cognitiveservices account managed-network outbound-rule remove'] = """
823+
type: command
824+
short-summary: Remove an outbound rule from the managed network.
825+
examples:
826+
- name: Remove an outbound rule.
827+
text: >
828+
az cognitiveservices account managed-network outbound-rule remove
829+
--name my-account
830+
--resource-group my-resource-group
831+
--rule my-rule
832+
"""
833+
834+
helps['cognitiveservices account managed-network outbound-rule set'] = """
835+
type: command
836+
short-summary: Create or update a single outbound rule for the managed network.
837+
long-summary: >
838+
Creates or updates an outbound rule of the specified type (FQDN, PrivateEndpoint, or ServiceTag).
839+
examples:
840+
- name: Create an FQDN outbound rule.
841+
text: >
842+
az cognitiveservices account managed-network outbound-rule set
843+
--name my-account
844+
--resource-group my-resource-group
845+
--rule my-fqdn-rule
846+
--type fqdn
847+
--destination "*.example.com"
848+
- name: Create a ServiceTag outbound rule.
849+
text: >
850+
az cognitiveservices account managed-network outbound-rule set
851+
--name my-account
852+
--resource-group my-resource-group
853+
--rule my-servicetag-rule
854+
--type servicetag
855+
--category UserDefined
856+
--destination '{"serviceTag": "Storage", "protocol": "TCP", "portRanges": "443"}'
857+
- name: Create a PrivateEndpoint outbound rule.
858+
text: >
859+
az cognitiveservices account managed-network outbound-rule set
860+
--name my-account
861+
--resource-group my-resource-group
862+
--rule my-pe-rule
863+
--type privateendpoint
864+
--destination /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.Storage/storageAccounts/mystorageaccount
865+
--subresource-target blob
866+
"""
867+
868+
helps['cognitiveservices account managed-network outbound-rule bulk-set'] = """
869+
type: command
870+
short-summary: Bulk create or update outbound rules from a YAML or JSON file.
871+
long-summary: >
872+
Reads outbound rules from a YAML or JSON file and creates or updates them in bulk.
873+
examples:
874+
- name: Bulk set outbound rules from a YAML file.
875+
text: >
876+
az cognitiveservices account managed-network outbound-rule bulk-set
877+
--name my-account
878+
--resource-group my-resource-group
879+
--file rules.yaml
880+
"""
881+
722882
helps['cognitiveservices account connection'] = """
723883
type: group
724884
short-summary: Manage Azure Cognitive Services connection and its more specific derivatives.

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,70 @@ def load_arguments(self, _):
688688
c.argument('next_count', help='Cognitive Services account commitment plan next commitment period count.')
689689
c.argument('next_tier', help='Cognitive Services account commitment plan next commitment period tier.')
690690

691+
with self.argument_context('cognitiveservices account managed-network') as c:
692+
c.argument('managed_network_name',
693+
options_list=['--managed-network-name'],
694+
help='Name of the managed network. Only "default" is supported.',
695+
default='default')
696+
697+
with self.argument_context('cognitiveservices account managed-network create') as c:
698+
c.argument('managed_network',
699+
options_list=['--managed-network'],
700+
arg_type=get_enum_type(['allow_internet_outbound', 'allow_only_approved_outbound']),
701+
help='Isolation mode for the managed network.',
702+
required=True)
703+
c.argument('firewall_sku',
704+
options_list=['--firewall-sku'],
705+
arg_type=get_enum_type(['Basic', 'Standard']),
706+
help='Firewall SKU for the managed network.')
707+
708+
with self.argument_context('cognitiveservices account managed-network update') as c:
709+
c.argument('managed_network',
710+
options_list=['--managed-network'],
711+
arg_type=get_enum_type(['allow_internet_outbound', 'allow_only_approved_outbound']),
712+
help='Isolation mode for the managed network.')
713+
c.argument('firewall_sku',
714+
options_list=['--firewall-sku'],
715+
arg_type=get_enum_type(['Basic', 'Standard']),
716+
help='Firewall SKU for the managed network.')
717+
718+
with self.argument_context('cognitiveservices account managed-network outbound-rule') as c:
719+
c.argument('managed_network_name',
720+
options_list=['--managed-network-name'],
721+
help='Name of the managed network. Only "default" is supported.',
722+
default='default',
723+
required=False)
724+
c.argument('rule_name',
725+
options_list=['--rule'],
726+
help='Name of the outbound rule.')
727+
728+
with self.argument_context('cognitiveservices account managed-network outbound-rule set') as c:
729+
c.argument('rule_type',
730+
options_list=['--type'],
731+
arg_type=get_enum_type(['fqdn', 'privateendpoint', 'servicetag']),
732+
help='Type of the outbound rule.',
733+
required=True)
734+
c.argument('category',
735+
options_list=['--category'],
736+
arg_type=get_enum_type(['Required', 'Recommended', 'UserDefined', 'Dependency']),
737+
help='Category of the outbound rule.')
738+
c.argument('destination',
739+
options_list=['--destination'],
740+
help='Destination for the outbound rule. '
741+
'For FQDN rules, this is the FQDN string. '
742+
'For PrivateEndpoint rules, this is the service resource ID. '
743+
'For ServiceTag rules, provide a JSON string.')
744+
c.argument('subresource_target',
745+
options_list=['--subresource-target'],
746+
help='Subresource target for PrivateEndpoint outbound rules '
747+
'(e.g. blob, table, queue, file, web, dfs).')
748+
749+
with self.argument_context('cognitiveservices account managed-network outbound-rule bulk-set') as c:
750+
c.argument('file',
751+
options_list=['--file'],
752+
help='Path to a YAML or JSON file containing outbound rules definition.',
753+
required=True)
754+
691755
with self.argument_context('cognitiveservices account project') as c:
692756
c.argument('project_name', help='Cognitive Services account project name')
693757
c.argument('location', arg_type=get_location_type(self.cli_ctx),

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def snake_to_camel(name):
3535
return re.sub(r"(?:^|_)([a-z])", lambda x: x.group(1).upper(), name)
3636

3737

38-
def get_auth_model_connection_properties(connection_category: str, auth_type: str | None, auth_params: Dict[str, Any]):
38+
def get_auth_model_connection_properties(connection_category: str, auth_type: str | None, auth_params: Dict[str, Any]): # pylint: disable=too-many-locals
3939
from azure.mgmt.cognitiveservices.models import (
4040
PATAuthTypeConnectionProperties,
4141
SASAuthTypeConnectionProperties,
@@ -60,40 +60,46 @@ def get_auth_model_connection_properties(connection_category: str, auth_type: st
6060
)
6161
# These categories were using None auth type with AzCLI ML connections
6262
CAN_USE_NONE_AUTH = [ConnectionCategory.GIT, ConnectionCategory.PYTHON_FEED]
63+
# SDK 15.x renamed some credential params; remap old names from YAML/JSON files
64+
_CREDENTIAL_PARAM_RENAMES = {
65+
'account_key': 'key',
66+
'sas_token': 'sas',
67+
}
68+
mapped_params = {_CREDENTIAL_PARAM_RENAMES.get(k, k): v for k, v in auth_params.items()}
6369
auth_model = None
6470
match snake_to_camel(auth_type):
6571
case "PersonalAccessToken" | "Pat":
6672
auth_model = PATAuthTypeConnectionProperties(
67-
credentials=ConnectionPersonalAccessToken(**auth_params))
73+
credentials=ConnectionPersonalAccessToken(**mapped_params))
6874
case "SasToken" | "Sas":
6975
auth_model = SASAuthTypeConnectionProperties(
70-
credentials=ConnectionSharedAccessSignature(**auth_params))
76+
credentials=ConnectionSharedAccessSignature(**mapped_params))
7177
case "UsernamePassword":
7278
auth_model = UsernamePasswordAuthTypeConnectionProperties(
73-
credentials=ConnectionUsernamePassword(**auth_params))
79+
credentials=ConnectionUsernamePassword(**mapped_params))
7480
case "ManagedIdentity":
7581
auth_model = ManagedIdentityAuthTypeConnectionProperties(
76-
credentials=ConnectionManagedIdentity(**auth_params))
82+
credentials=ConnectionManagedIdentity(**mapped_params))
7783
case "ServicePrincipal":
7884
auth_model = ServicePrincipalAuthTypeConnectionProperties(
79-
credentials=ConnectionServicePrincipal(**auth_params))
85+
credentials=ConnectionServicePrincipal(**mapped_params))
8086
case "AccessKey":
8187
auth_model = AccessKeyAuthTypeConnectionProperties(
82-
credentials=ConnectionAccessKey(**auth_params))
88+
credentials=ConnectionAccessKey(**mapped_params))
8389
case "ApiKey":
8490
auth_model = ApiKeyAuthConnectionProperties(
85-
credentials=ConnectionApiKey(**auth_params))
91+
credentials=ConnectionApiKey(**mapped_params))
8692
case "OAuth2":
8793
auth_model = OAuth2AuthTypeConnectionProperties(
88-
credentials=ConnectionOAuth2(**auth_params))
94+
credentials=ConnectionOAuth2(**mapped_params))
8995
case "None":
9096
if connection_category in CAN_USE_NONE_AUTH:
9197
auth_model = NoneAuthTypeConnectionProperties()
9298
else:
9399
auth_model = AADAuthTypeConnectionProperties()
94100
case "AccountKey":
95101
auth_model = AccountKeyAuthTypeConnectionProperties(
96-
credentials=ConnectionAccountKey(**auth_params))
102+
credentials=ConnectionAccountKey(**mapped_params))
97103
case "Aad":
98104
auth_model = AADAuthTypeConnectionProperties()
99105

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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
from azure.cli.core.commands import CliCommandType
77
from azure.cli.command_modules.cognitiveservices._client_factory import cf_accounts, cf_resource_skus, \
88
cf_deleted_accounts, cf_deployments, cf_commitment_plans, cf_commitment_tiers, cf_models, cf_usages, \
9-
cf_ai_projects, cf_account_connections, cf_projects, cf_project_connections
9+
cf_ai_projects, cf_account_connections, cf_projects, cf_project_connections, \
10+
cf_managed_network_settings, cf_managed_network_provisions, cf_outbound_rule
1011

1112

1213
def load_command_table(self, _):
@@ -76,7 +77,7 @@ def load_command_table(self, _):
7677
g.custom_command('list-kinds', 'list_kinds', client_factory=cf_resource_skus)
7778

7879
with self.command_group('cognitiveservices account keys', accounts_type) as g:
79-
g.command('regenerate', 'regenerate_key')
80+
g.custom_command('regenerate', 'regenerate_key')
8081
g.command('list', 'list_keys')
8182

8283
# deprecating this
@@ -134,11 +135,39 @@ def load_command_table(self, _):
134135
with self.command_group('cognitiveservices agent logs', client_factory=cf_ai_projects, is_preview=True) as g:
135136
g.custom_show_command('show', 'agent_logs_show')
136137

138+
managed_network_settings_type = CliCommandType(
139+
operations_tmpl='azure.mgmt.cognitiveservices.operations#ManagedNetworkSettingsOperations.{}',
140+
client_factory=cf_managed_network_settings
141+
)
142+
143+
outbound_rule_type = CliCommandType(
144+
operations_tmpl='azure.mgmt.cognitiveservices.operations#OutboundRuleOperations.{}',
145+
client_factory=cf_outbound_rule
146+
)
147+
148+
with self.command_group(
149+
'cognitiveservices account managed-network', managed_network_settings_type,
150+
client_factory=cf_managed_network_settings, is_preview=True) as g:
151+
g.custom_command('create', 'managed_network_create')
152+
g.custom_command('update', 'managed_network_update')
153+
g.custom_show_command('show', 'managed_network_show')
154+
g.custom_command('provision-network', 'managed_network_provision',
155+
client_factory=cf_managed_network_provisions)
156+
157+
with self.command_group(
158+
'cognitiveservices account managed-network outbound-rule', outbound_rule_type,
159+
client_factory=cf_outbound_rule, is_preview=True) as g:
160+
g.command('list', 'list')
161+
g.show_command('show', 'get')
162+
g.custom_command('remove', 'outbound_rule_remove', confirmation=True)
163+
g.custom_command('set', 'outbound_rule_set')
164+
g.custom_command('bulk-set', 'outbound_rule_bulk_set')
165+
137166
with self.command_group(
138167
'cognitiveservices account project', projects_type,
139168
client_factory=cf_projects) as g:
140169
g.custom_command('create', 'project_create')
141-
g.command('delete', 'begin_delete')
170+
g.custom_command('delete', 'project_delete')
142171
g.show_command('show', 'get')
143172
g.command('list', 'list')
144173
g.custom_command('update', 'project_update')

0 commit comments

Comments
 (0)