Skip to content
Closed
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 @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Loading