From b5b1a2b892073a58e720c34578a05d78d8b30986 Mon Sep 17 00:00:00 2001 From: Johan Stenberg Date: Tue, 28 Oct 2025 14:54:40 -0700 Subject: [PATCH 1/2] Agent application deployment start/stop cli commands for cogsvc --- .../cognitiveservices/_client_factory.py | 16 +++++++++++++ .../cognitiveservices/_params.py | 4 ++++ .../cognitiveservices/commands.py | 11 ++++++++- .../cognitiveservices/custom.py | 23 +++++++++++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) 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..40622d4d26e 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,19 @@ def cf_models(cli_ctx, *_): def cf_usages(cli_ctx, *_): return get_cognitiveservices_management_client(cli_ctx).usages + +class ApplicationClient: + def __init__(self, cli_ctx): + self.client = get_cognitiveservices_management_client(cli_ctx) + + def start(self, *,resource_group_name: str, account_name: str): + # Placeholder implementation for starting application deployment + return f"Starting application deployment for account '{account_name}' in resource group '{resource_group_name}'." + + def stop(self, *, resource_group_name: str, account_name: str): + # Placeholder implementation for stopping application deployment + return f"Stopping application deployment for account '{account_name}' in resource group '{resource_group_name}'." + +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..b9841396625 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,26 @@ 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-11-15-preview'} + ) + response = client._send_request( + request + ) + response.raise_for_status() + +def application_deployment_start(client, resource_group_name, account_name, application_name, application_deployment_name): + return _application_deployment_command(client, resource_group_name, account_name, application_name, application_deployment_name, 'start') + +def application_deployment_stop(client, resource_group_name, account_name, application_name, application_deployment_name): + return _application_deployment_command(client, resource_group_name, account_name, application_name, application_deployment_name, 'stop') + From bc02aab516d09371fbaa98c92b2ad0f3467b8c5f Mon Sep 17 00:00:00 2001 From: Johan Stenberg Date: Tue, 28 Oct 2025 15:06:33 -0700 Subject: [PATCH 2/2] Fix up apiversion and argnames for app deployment start/stop --- .../cognitiveservices/_client_factory.py | 12 ------------ .../cli/command_modules/cognitiveservices/custom.py | 12 +++++++----- 2 files changed, 7 insertions(+), 17 deletions(-) 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 40622d4d26e..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 @@ -41,18 +41,6 @@ def cf_models(cli_ctx, *_): def cf_usages(cli_ctx, *_): return get_cognitiveservices_management_client(cli_ctx).usages -class ApplicationClient: - def __init__(self, cli_ctx): - self.client = get_cognitiveservices_management_client(cli_ctx) - - def start(self, *,resource_group_name: str, account_name: str): - # Placeholder implementation for starting application deployment - return f"Starting application deployment for account '{account_name}' in resource group '{resource_group_name}'." - - def stop(self, *, resource_group_name: str, account_name: str): - # Placeholder implementation for stopping application deployment - return f"Stopping application deployment for account '{account_name}' in resource group '{resource_group_name}'." - 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/custom.py b/src/azure-cli/azure/cli/command_modules/cognitiveservices/custom.py index b9841396625..5f054200d7d 100644 --- a/src/azure-cli/azure/cli/command_modules/cognitiveservices/custom.py +++ b/src/azure-cli/azure/cli/command_modules/cognitiveservices/custom.py @@ -335,16 +335,18 @@ def _application_deployment_command(client, resource_group_name, account_name, a 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-11-15-preview'} + 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, application_name, application_deployment_name): - return _application_deployment_command(client, resource_group_name, account_name, application_name, application_deployment_name, 'start') +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, application_name, application_deployment_name): - return _application_deployment_command(client, resource_group_name, account_name, application_name, application_deployment_name, 'stop') +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')