Skip to content

Commit 672c617

Browse files
author
Seth
committed
Quota validation - added pwsh versions to make deploying from windows easier
1 parent 057175e commit 672c617

3 files changed

Lines changed: 148 additions & 4 deletions

File tree

azure.yaml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ hooks:
1111
interactive: true
1212
continueOnError: false
1313
preprovision:
14-
shell: sh
15-
run: ./scripts/validate_model_deployment_quotas.sh --subscription $AZURE_SUBSCRIPTION_ID --location $AZURE_LOCATION --models-parameter "aiModelDeployments"
16-
interactive: false
17-
continueOnError: false
14+
posix:
15+
shell: sh
16+
run: ./scripts/validate_model_deployment_quotas.sh --subscription $AZURE_SUBSCRIPTION_ID --location $AZURE_LOCATION --models-parameter "aiModelDeployments"
17+
interactive: false
18+
continueOnError: false
19+
windows:
20+
shell: pwsh
21+
run: ./scripts/validate_model_deployment_quotas.ps1 -Subscription $env:AZURE_SUBSCRIPTION_ID -Location $env:AZURE_LOCATION -ModelsParameter "aiModelDeployments"
22+
interactive: false
23+
continueOnError: false
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
param (
2+
[string]$SubscriptionId,
3+
[string]$Location,
4+
[string]$ModelsParameter
5+
)
6+
7+
# Verify all required parameters are provided
8+
$MissingParams = @()
9+
10+
if (-not $SubscriptionId) {
11+
$MissingParams += "subscription"
12+
}
13+
14+
if (-not $Location) {
15+
$MissingParams += "location"
16+
}
17+
18+
if (-not $ModelsParameter) {
19+
$MissingParams += "models-parameter"
20+
}
21+
22+
if ($MissingParams.Count -gt 0) {
23+
Write-Error "❌ ERROR: Missing required parameters: $($MissingParams -join ', ')"
24+
Write-Host "Usage: .\validate_model_deployment_quotas.ps1 -SubscriptionId <SUBSCRIPTION_ID> -Location <LOCATION> -ModelsParameter <MODELS_PARAMETER>"
25+
exit 1
26+
}
27+
28+
$JsonContent = Get-Content -Path "./infra/main.parameters.json" -Raw | ConvertFrom-Json
29+
30+
if (-not $JsonContent) {
31+
Write-Error "❌ ERROR: Failed to parse main.parameters.json. Ensure the JSON file is valid."
32+
exit 1
33+
}
34+
35+
$aiModelDeployments = $JsonContent.parameters.$ModelsParameter.value
36+
37+
if (-not $aiModelDeployments -or -not ($aiModelDeployments -is [System.Collections.IEnumerable])) {
38+
Write-Error "❌ ERROR: The specified property $ModelsParameter does not exist or is not an array."
39+
exit 1
40+
}
41+
42+
# Set the Azure subscription
43+
az account set --subscription $SubscriptionId
44+
Write-Host "🎯 Active Subscription: $(az account show --query '[name, id]' --output tsv)"
45+
46+
$QuotaAvailable = $true
47+
48+
# Iterate over each deployment in the aiModelDeployments array
49+
foreach ($deployment in $aiModelDeployments) {
50+
$name = $deployment.name
51+
$model = $deployment.model.name
52+
$type = $deployment.sku.name
53+
$capacity = $deployment.sku.capacity
54+
55+
# Call the validate_model_quota.ps1 script
56+
Write-Host "🔍 Validating model deployment: $name ..."
57+
& .\scripts\validate_model_quota.ps1 -Location $Location -Model $model -Capacity $capacity -DeploymentType $type
58+
59+
# Check if the script failed
60+
if ($LASTEXITCODE -ne 0) {
61+
Write-Error "❌ ERROR: Quota validation failed for model deployment: $name"
62+
$QuotaAvailable = $false
63+
}
64+
}
65+
66+
if (-not $QuotaAvailable) {
67+
Write-Error "❌ ERROR: One or more model deployments failed validation."
68+
exit 1
69+
} else {
70+
Write-Host "✅ All model deployments passed quota validation successfully."
71+
exit 0
72+
}

scripts/validate_model_quota.ps1

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
param (
2+
[string]$Location,
3+
[string]$Model,
4+
[string]$DeploymentType = "Standard",
5+
[int]$Capacity
6+
)
7+
8+
# Verify all required parameters are provided
9+
$MissingParams = @()
10+
11+
if (-not $Location) {
12+
$MissingParams += "location"
13+
}
14+
15+
if (-not $Model) {
16+
$MissingParams += "model"
17+
}
18+
19+
if (-not $Capacity) {
20+
$MissingParams += "capacity"
21+
}
22+
23+
if (-not $DeploymentType) {
24+
$MissingParams += "deployment-type"
25+
}
26+
27+
if ($MissingParams.Count -gt 0) {
28+
Write-Error "❌ ERROR: Missing required parameters: $($MissingParams -join ', ')"
29+
Write-Host "Usage: .\validate_model_quota.ps1 -Location <LOCATION> -Model <MODEL> -Capacity <CAPACITY> [-DeploymentType <DEPLOYMENT_TYPE>]"
30+
exit 1
31+
}
32+
33+
if ($DeploymentType -ne "Standard" -and $DeploymentType -ne "GlobalStandard") {
34+
Write-Error "❌ ERROR: Invalid deployment type: $DeploymentType. Allowed values are 'Standard' or 'GlobalStandard'."
35+
exit 1
36+
}
37+
38+
$ModelType = "OpenAI.$DeploymentType.$Model"
39+
40+
Write-Host "🔍 Checking quota for $ModelType in $Location ..."
41+
42+
# Get quota information using Azure CLI
43+
$ModelInfo = az cognitiveservices usage list --location $Location --query "[?name.value=='$ModelType']" --output json | ConvertFrom-Json
44+
45+
if (-not $ModelInfo) {
46+
Write-Error "❌ ERROR: No quota information found for model: $Model in location: $Location for model type: $ModelType."
47+
exit 1
48+
}
49+
50+
if ($ModelInfo) {
51+
$CurrentValue = ($ModelInfo | Where-Object { $_.name.value -eq $ModelType }).currentValue
52+
$Limit = ($ModelInfo | Where-Object { $_.name.value -eq $ModelType }).limit
53+
54+
$CurrentValue = [int]($CurrentValue -replace '\.0+$', '') # Remove decimals
55+
$Limit = [int]($Limit -replace '\.0+$', '') # Remove decimals
56+
57+
$Available = $Limit - $CurrentValue
58+
Write-Host "✅ Model available - Model: $ModelType | Used: $CurrentValue | Limit: $Limit | Available: $Available"
59+
60+
if ($Available -lt $Capacity) {
61+
Write-Error "❌ ERROR: Insufficient quota for model: $Model in location: $Location. Available: $Available, Requested: $Capacity."
62+
exit 1
63+
} else {
64+
Write-Host "✅ Sufficient quota for model: $Model in location: $Location. Available: $Available, Requested: $Capacity."
65+
}
66+
}

0 commit comments

Comments
 (0)