Skip to content
Open
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
8 changes: 8 additions & 0 deletions src/foundry-cost-control/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. :changelog:

Release History
===============

1.0.0b1
++++++
* Initial release.
75 changes: 75 additions & 0 deletions src/foundry-cost-control/PostEmitter.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#
# Run this script after re-emitting the code:
# powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\PostEmitter.ps1
#

# Change 1:
# I did manual edits to README.md and setup.py files. Make sure you restore
# this version after you re-emit

& git -C $PSScriptRoot restore -- README.md
if ($LASTEXITCODE -ne 0) {
throw "Failed to restore README.md after CLI emission."
}

& git -C $PSScriptRoot restore -- setup.py
if ($LASTEXITCODE -ne 0) {
throw "Failed to restore setup.py after CLI emission."
}

# Change 2:
# Replaces 2026-09-15-preview with 2026-07-15-preview in azext_foundry_cost_control
# and its subfolders, excluding azext_foundry_cost_control\tests.
# Run from Windows Command Prompt:
# powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\PostEmitter.ps1

$ErrorActionPreference = 'Stop'

$oldValue = [System.Text.Encoding]::ASCII.GetBytes('2026-09-15-preview')
$newValue = [System.Text.Encoding]::ASCII.GetBytes('2026-07-15-preview')
$targetDirectory = Join-Path $PSScriptRoot 'azext_foundry_cost_control'
$excludedDirectory = [System.IO.Path]::GetFullPath(
(Join-Path $targetDirectory 'tests')
).TrimEnd('\') + '\'
$updatedFileCount = 0
$replacementCount = 0

Get-ChildItem -LiteralPath $targetDirectory -File -Recurse | ForEach-Object {
$filePath = [System.IO.Path]::GetFullPath($_.FullName)
if ($filePath.StartsWith($excludedDirectory, [System.StringComparison]::OrdinalIgnoreCase)) {
return
}

$content = [System.IO.File]::ReadAllBytes($filePath)
$fileReplacementCount = 0

for ($index = 0; $index -le $content.Length - $oldValue.Length; $index++) {
$matches = $true
for ($offset = 0; $offset -lt $oldValue.Length; $offset++) {
if ($content[$index + $offset] -ne $oldValue[$offset]) {
$matches = $false
break
}
}

if ($matches) {
[System.Array]::Copy($newValue, 0, $content, $index, $newValue.Length)
$fileReplacementCount++
$index += $oldValue.Length - 1
}
}

if ($fileReplacementCount -gt 0) {
[System.IO.File]::WriteAllBytes($filePath, $content)
$updatedFileCount++
$replacementCount += $fileReplacementCount
Write-Host "Updated: $filePath ($fileReplacementCount replacement(s))"
}
}

Write-Host "Complete: $replacementCount replacement(s) in $updatedFileCount file(s)."

# Change 3:
# Use CoPilot to fix an emitter bug (?). Use this prompt:
# Run "cls & azdev test foundry-cost-control --live --debug" and fix the resulting error. A similar fix was made in the past, so you can look at this commit for reference: https://github.com/Azure/azure-cli-extensions/pull/10298/changes/d981f14597cdcd118c3ab7b17264057944496a97
#
19 changes: 19 additions & 0 deletions src/foundry-cost-control/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Azure CLI Foundry Cost Control Extension

This is an extension to Azure CLI to manage Foundry Cost Control policies.

## How to use

Add the extension:

```
az extension add --name foundry-cost-control
```

Get help on the commands:

```
az cognitive-services account cost-control --help
```

For usage examples see the test file `azext_foundry_cost_control/tests/latest/test_foundry_cost_control.py`.
42 changes: 42 additions & 0 deletions src/foundry-cost-control/azext_foundry_cost_control/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

from azure.cli.core import AzCommandsLoader
from azext_foundry_cost_control._help import helps # pylint: disable=unused-import


class FoundryCostControlCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
custom_command_type = CliCommandType(
operations_tmpl='azext_foundry_cost_control.custom#{}')
super().__init__(cli_ctx=cli_ctx,
custom_command_type=custom_command_type)

def load_command_table(self, args):
from azext_foundry_cost_control.commands import load_command_table
from azure.cli.core.aaz import load_aaz_command_table
try:
from . import aaz
except ImportError:
aaz = None
if aaz:
load_aaz_command_table(
loader=self,
aaz_pkg_name=aaz.__name__,
args=args
)
load_command_table(self, args)
return self.command_table

def load_arguments(self, command):
from azext_foundry_cost_control._params import load_arguments
load_arguments(self, command)


COMMAND_LOADER_CLS = FoundryCostControlCommandsLoader
11 changes: 11 additions & 0 deletions src/foundry-cost-control/azext_foundry_cost_control/_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: disable=line-too-long
# pylint: disable=too-many-lines

from knack.help_files import helps # pylint: disable=unused-import
13 changes: 13 additions & 0 deletions src/foundry-cost-control/azext_foundry_cost_control/_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: disable=too-many-lines
# pylint: disable=too-many-statements


def load_arguments(self, _): # pylint: disable=unused-argument
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from azure.cli.core.aaz import *


@register_command_group(
"cognitive-services",
is_preview=True,
)
class __CMDGroup(AAZCommandGroup):
"""Manage Cognitive Services
"""
pass


__all__ = ["__CMDGroup"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from .__cmd_group import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from azure.cli.core.aaz import *


@register_command_group(
"cognitive-services account",
is_preview=True,
)
class __CMDGroup(AAZCommandGroup):
"""Manage Account
"""
pass


__all__ = ["__CMDGroup"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from .__cmd_group import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from azure.cli.core.aaz import *


@register_command_group(
"cognitive-services account cost-control",
is_preview=True,
)
class __CMDGroup(AAZCommandGroup):
"""Manage Cost Control Policies in Foundry

A set of commands to manage Cost Control Policies in Foundry. Supported commands are `create`, `delete`, `list`, `show` and `update`. Use those policies to set a threshold on the cost (in USD) per time period for token use by your AI model or account. You can also set alerts to get notified when this threshold approaches.
"""
pass


__all__ = ["__CMDGroup"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from .__cmd_group import *
from ._create import *
from ._delete import *
from ._list import *
from ._show import *
from ._update import *
Loading
Loading