Skip to content

Commit c9e541b

Browse files
updated the output
1 parent 91d67a6 commit c9e541b

File tree

2 files changed

+75
-73
lines changed

2 files changed

+75
-73
lines changed

infra/scripts/validate_model_quota.ps1

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,69 +25,80 @@ if ($DeploymentType -ne "Standard" -and $DeploymentType -ne "GlobalStandard") {
2525

2626
$ModelType = "OpenAI.$DeploymentType.$Model"
2727

28+
$PreferredRegions = @('australiaeast', 'eastus2', 'francecentral', 'japaneast', 'norwayeast', 'swedencentral', 'uksouth', 'westus')
29+
$AllResults = @()
30+
2831
function Check-Quota {
2932
param (
3033
[string]$Region
3134
)
3235

33-
Write-Host "`n🔍 Checking quota for $ModelType in $Region ..."
34-
3536
$ModelInfoRaw = az cognitiveservices usage list --location $Region --query "[?name.value=='$ModelType']" --output json
3637
$ModelInfo = $null
3738

3839
try {
3940
$ModelInfo = $ModelInfoRaw | ConvertFrom-Json
4041
} catch {
41-
Write-Warning "⚠️ Failed to parse quota info for region: $Region"
42-
return $false
42+
return
4343
}
4444

4545
if (-not $ModelInfo) {
46-
Write-Host "⚠️ No quota information found for $ModelType in $Region"
47-
return $false
46+
return
4847
}
4948

5049
$CurrentValue = ($ModelInfo | Where-Object { $_.name.value -eq $ModelType }).currentValue
5150
$Limit = ($ModelInfo | Where-Object { $_.name.value -eq $ModelType }).limit
5251

53-
$CurrentValue = [int]($CurrentValue -replace '\.0+$', '') # Remove decimals
54-
$Limit = [int]($Limit -replace '\.0+$', '') # Remove decimals
55-
52+
$CurrentValue = [int]($CurrentValue -replace '\.0+$', '')
53+
$Limit = [int]($Limit -replace '\.0+$', '')
5654
$Available = $Limit - $CurrentValue
57-
Write-Host "🔎 Model: $ModelType | Used: $CurrentValue | Limit: $Limit | Available: $Available"
58-
59-
if ($Available -ge $Capacity) {
60-
Write-Host "✅ Sufficient quota in $Region"
61-
return $true
62-
} else {
63-
Write-Host "❌ Insufficient quota in $Region (Available: $Available, Required: $Capacity)"
64-
return $false
55+
56+
$script:AllResults += [PSCustomObject]@{
57+
Region = $Region
58+
Model = $ModelType
59+
Limit = $Limit
60+
Used = $CurrentValue
61+
Available = $Available
6562
}
6663
}
6764

68-
# List of fallback regions (excluding the one already tried)
69-
$PreferredRegions = @('australiaeast', 'eastus2', 'francecentral', 'japaneast', 'norwayeast', 'swedencentral', 'uksouth', 'westus') | Where-Object { $_ -ne $Location }
65+
foreach ($region in $PreferredRegions) {
66+
Check-Quota -Region $region
67+
}
7068

71-
# Try original location first
72-
if (Check-Quota -Region $Location) {
69+
# Display Results Table
70+
Write-Host "\n-------------------------------------------------------------------------------------------------------------"
71+
Write-Host "| No. | Region | Model Name | Limit | Used | Available |"
72+
Write-Host "-------------------------------------------------------------------------------------------------------------"
73+
74+
$count = 1
75+
foreach ($entry in $AllResults) {
76+
$index = $PreferredRegions.IndexOf($entry.Region) + 1
77+
$modelShort = $entry.Model.Substring($entry.Model.LastIndexOf(".") + 1)
78+
Write-Host ("| {0,-4} | {1,-16} | {2,-35} | {3,-7} | {4,-7} | {5,-9} |" -f $index, $entry.Region, $entry.Model, $entry.Limit, $entry.Used, $entry.Available)
79+
$count++
80+
}
81+
Write-Host "-------------------------------------------------------------------------------------------------------------"
82+
83+
$EligibleRegion = $AllResults | Where-Object { $_.Region -eq $Location -and $_.Available -ge $Capacity }
84+
if ($EligibleRegion) {
85+
Write-Host "\n✅ Sufficient quota found in original region '$Location'."
7386
exit 0
7487
}
7588

76-
Write-Host "`n🔁 Trying fallback regions for available quota..."
89+
$FallbackRegions = $AllResults | Where-Object { $_.Region -ne $Location -and $_.Available -ge $Capacity }
7790

78-
foreach ($region in $PreferredRegions) {
79-
if (Check-Quota -Region $region) {
80-
Write-Host "🚫 Deployment cannot proceed because the original region '$Location' lacks sufficient quota."
81-
Write-Host "➡️ You can retry using the available region: '$region'"
82-
Write-Host "🔧 To proceed, update the 'AZURE_OPENAI_LOCATION' value in the 'main.bicepparam' file, then run the following command:"
83-
Write-Host " azd env set AZURE_OPENAI_LOCATION '$region'"
91+
if ($FallbackRegions.Count -gt 0) {
92+
Write-Host "`n❌ Deployment cannot proceed because the original region '$Location' lacks sufficient quota."
93+
Write-Host "➡️ You can retry using one of the following regions with sufficient quota:`n"
8494

85-
# Optional: update `.azure/env` (uncomment if needed)
86-
# Add-Content ".azure/env" "`nAZURE_OPENAI_LOCATION=$region"
87-
88-
# Exit with non-zero code to halt deployment
89-
exit 2
95+
foreach ($region in $FallbackRegions) {
96+
Write-Host "$($region.Region) (Available: $($region.Available))"
9097
}
98+
99+
Write-Host "`n🔧 To proceed, update the 'AZURE_OPENAI_LOCATION' value in the 'main.bicepparam' file, then run:"
100+
Write-Host " azd env set AZURE_OPENAI_LOCATION '<region>'"
101+
exit 2
91102
}
92103

93104
Write-Error "❌ ERROR: No available quota found in any region."

infra/scripts/validate_model_quota.sh

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -51,56 +51,47 @@ fi
5151

5252
MODEL_TYPE="OpenAI.$DEPLOYMENT_TYPE.$MODEL"
5353

54-
check_quota() {
55-
local region="$1"
56-
echo "🔍 Checking quota for $MODEL_TYPE in $region ..."
54+
declare -a FALLBACK_REGIONS=()
55+
ROW_NO=1
5756

57+
printf "\n%-5s | %-20s | %-40s | %-10s | %-10s | %-10s\n" "No." "Region" "Model Name" "Limit" "Used" "Available"
58+
printf -- "---------------------------------------------------------------------------------------------------------------------\n"
59+
60+
for region in "${ALL_REGIONS[@]}"; do
5861
MODEL_INFO=$(az cognitiveservices usage list --location "$region" --query "[?name.value=='$MODEL_TYPE']" --output json 2>/dev/null)
5962

60-
if [[ -z "$MODEL_INFO" || "$MODEL_INFO" == "[]" ]]; then
61-
echo "⚠️ No quota info found for $MODEL_TYPE in $region"
62-
return 1
63-
fi
63+
if [[ -n "$MODEL_INFO" && "$MODEL_INFO" != "[]" ]]; then
64+
CURRENT_VALUE=$(echo "$MODEL_INFO" | jq -r '.[0].currentValue // 0' | cut -d'.' -f1)
65+
LIMIT=$(echo "$MODEL_INFO" | jq -r '.[0].limit // 0' | cut -d'.' -f1)
66+
AVAILABLE=$((LIMIT - CURRENT_VALUE))
6467

65-
CURRENT_VALUE=$(echo "$MODEL_INFO" | jq -r '.[0].currentValue // 0' | cut -d'.' -f1)
66-
LIMIT=$(echo "$MODEL_INFO" | jq -r '.[0].limit // 0' | cut -d'.' -f1)
67-
AVAILABLE=$((LIMIT - CURRENT_VALUE))
68+
printf "%-5s | %-20s | %-40s | %-10s | %-10s | %-10s\n" "$ROW_NO" "$region" "$MODEL_TYPE" "$LIMIT" "$CURRENT_VALUE" "$AVAILABLE"
6869

69-
echo "🔎 Model: $MODEL_TYPE | Used: $CURRENT_VALUE | Limit: $LIMIT | Available: $AVAILABLE"
70+
if [[ "$region" == "$LOCATION" && "$AVAILABLE" -ge "$CAPACITY" ]]; then
71+
echo -e "\n✅ Sufficient quota available in user-specified region: $LOCATION"
72+
exit 0
73+
fi
7074

71-
if (( AVAILABLE >= CAPACITY )); then
72-
echo "✅ Sufficient quota in $region"
73-
return 0
74-
else
75-
echo "❌ Insufficient quota in $region (Available: $AVAILABLE, Required: $CAPACITY)"
76-
return 1
75+
if [[ "$region" != "$LOCATION" && "$AVAILABLE" -ge "$CAPACITY" ]]; then
76+
FALLBACK_REGIONS+=("$region ($AVAILABLE)")
77+
fi
7778
fi
78-
}
7979

80-
# Try user-provided region
81-
if check_quota "$LOCATION"; then
82-
exit 0
83-
fi
84-
85-
# Try fallback regions
86-
REMAINING_REGIONS=()
87-
for region in "${ALL_REGIONS[@]}"; do
88-
if [[ "$region" != "$LOCATION" ]]; then
89-
REMAINING_REGIONS+=("$region")
90-
fi
80+
((ROW_NO++))
9181
done
9282

93-
echo "🔁 Trying fallback regions for available quota..."
94-
95-
for region in "${REMAINING_REGIONS[@]}"; do
96-
if check_quota "$region"; then
97-
echo "🚫 Deployment cannot proceed because the original region '$LOCATION' lacks sufficient quota."
98-
echo "➡️ You can retry using the available region: '$region'"
99-
echo "🔧 To proceed, update the 'AZURE_OPENAI_LOCATION' value in the 'main.bicepparam' file, then run:"
100-
echo " azd env set AZURE_OPENAI_LOCATION '$region'"
101-
exit 1
102-
fi
103-
done
83+
printf -- "---------------------------------------------------------------------------------------------------------------------\n"
84+
85+
if [[ "${#FALLBACK_REGIONS[@]}" -gt 0 ]]; then
86+
echo -e "\n❌ Deployment cannot proceed because the original region '$LOCATION' lacks sufficient quota."
87+
echo "➡️ You can retry using one of the following regions with sufficient quota:"
88+
for fallback in "${FALLBACK_REGIONS[@]}"; do
89+
echo "$fallback"
90+
done
91+
echo -e "\n🔧 To proceed, update the 'AZURE_OPENAI_LOCATION' value in the 'main.bicepparam' file, then run:"
92+
echo " azd env set AZURE_OPENAI_LOCATION '<region>'"
93+
exit 2
94+
fi
10495

10596
echo "❌ ERROR: No available quota found in any of the fallback regions."
10697
exit 1

0 commit comments

Comments
 (0)