diff --git a/src/azure-cli/azure/cli/command_modules/cognitiveservices/_client_factory.py b/src/azure-cli/azure/cli/command_modules/cognitiveservices/_client_factory.py index a31eed3f200..1dc069c9107 100644 --- a/src/azure-cli/azure/cli/command_modules/cognitiveservices/_client_factory.py +++ b/src/azure-cli/azure/cli/command_modules/cognitiveservices/_client_factory.py @@ -40,3 +40,7 @@ def cf_models(cli_ctx, *_): def cf_usages(cli_ctx, *_): return get_cognitiveservices_management_client(cli_ctx).usages + +def cf_application(cli_ctx, *_): + print('cf_application called') + return get_cognitiveservices_management_client(cli_ctx) diff --git a/src/azure-cli/azure/cli/command_modules/cognitiveservices/_params.py b/src/azure-cli/azure/cli/command_modules/cognitiveservices/_params.py index 7f6183eba58..42f56ec1f65 100644 --- a/src/azure-cli/azure/cli/command_modules/cognitiveservices/_params.py +++ b/src/azure-cli/azure/cli/command_modules/cognitiveservices/_params.py @@ -214,3 +214,7 @@ def load_arguments(self, _): with self.argument_context('cognitiveservices account commitment-plan', arg_group='Next CommitmentPeriod') as c: c.argument('next_count', help='Cognitive Services account commitment plan next commitment period count.') c.argument('next_tier', help='Cognitive Services account commitment plan next commitment period tier.') + + with self.argument_context('cognitiveservices application') as c: + c.argument('application_name', help='Cognitive Services application name') + \ No newline at end of file diff --git a/src/azure-cli/azure/cli/command_modules/cognitiveservices/commands.py b/src/azure-cli/azure/cli/command_modules/cognitiveservices/commands.py index 53b736838c0..ffd42aeb36d 100644 --- a/src/azure-cli/azure/cli/command_modules/cognitiveservices/commands.py +++ b/src/azure-cli/azure/cli/command_modules/cognitiveservices/commands.py @@ -4,7 +4,7 @@ # -------------------------------------------------------------------------------------------- from azure.cli.core.commands import CliCommandType -from azure.cli.command_modules.cognitiveservices._client_factory import cf_accounts, cf_resource_skus, \ +from azure.cli.command_modules.cognitiveservices._client_factory import cf_accounts, cf_application, cf_resource_skus, \ cf_deleted_accounts, cf_deployments, cf_commitment_plans, cf_commitment_tiers, cf_models, cf_usages @@ -39,6 +39,11 @@ def load_command_table(self, _): client_factory=cf_usages ) + applications_type = CliCommandType( + # operations_tmpl='azure.cli.command_modules.cognitiveservices.commands#ApplicationClient.{}', + client_factory=cf_application + ) + with self.command_group('cognitiveservices account', accounts_type, client_factory=cf_accounts) as g: g.custom_command('create', 'create') g.command('delete', 'begin_delete') @@ -103,3 +108,7 @@ def load_command_table(self, _): with self.command_group('cognitiveservices usage', usages_type) as g: g.command('list', 'list') + + with self.command_group('cognitiveservices application', applications_type) as g: + g.custom_command('start', 'application_deployment_start', client_factory=cf_application) + g.custom_command('stop', 'application_deployment_stop', client_factory=cf_application) diff --git a/src/azure-cli/azure/cli/command_modules/cognitiveservices/custom.py b/src/azure-cli/azure/cli/command_modules/cognitiveservices/custom.py index fce86c7988f..5f054200d7d 100644 --- a/src/azure-cli/azure/cli/command_modules/cognitiveservices/custom.py +++ b/src/azure-cli/azure/cli/command_modules/cognitiveservices/custom.py @@ -325,3 +325,28 @@ def commitment_plan_create_or_update( plan.properties.next.count = next_count plan.properties.auto_renew = auto_renew return client.create_or_update(resource_group_name, account_name, commitment_plan_name, plan) + +def _app_deployment_url(client, resource_group_name, account_name, application_name, application_deployment_name): + url = f"/subscriptions/{client._config.subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.CognitiveServices/accounts/{account_name}/applications/{application_name}/deployments/{application_deployment_name}" + return url + +def _application_deployment_command(client, resource_group_name, account_name, application_name, application_deployment_name, opname): + import azure.core.rest + request = azure.core.rest.HttpRequest( + method="POST", + url=_app_deployment_url(client, resource_group_name, account_name, application_name, application_deployment_name) + f"/{opname}", + params={'api-version': '2025-10-01-preview'} + ) + response = client._send_request( + request + ) + response.raise_for_status() + +def application_deployment_start(client, resource_group_name, account_name, appname, appdeploymentname): + """Start an application deployment.""" + return _application_deployment_command(client, resource_group_name, account_name, appname, appdeploymentname, 'start') + +def application_deployment_stop(client, resource_group_name, account_name, appname, appdeploymentname): + """Stop an application deployment.""" + return _application_deployment_command(client, resource_group_name, account_name, appname, appdeploymentname, 'stop') +