Skip to content

Commit f395a43

Browse files
script updated
1 parent 9ee00bd commit f395a43

3 files changed

Lines changed: 86 additions & 57 deletions

File tree

azure.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ hooks:
3535
run: >
3636
$location = if ($env:AZURE_AISERVICE_LOCATION) { $env:AZURE_AISERVICE_LOCATION } else { "japaneast" };
3737
./scripts/validate_model_deployment_quota.ps1 -SubscriptionId $env:AZURE_SUBSCRIPTION_ID -Location $location -ModelsParameter "aiModelDeployments"
38-
interactive: false
38+
interactive: true
3939
continueOnError: false

scripts/validate_model_quota.ps1

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ $MissingParams = @()
1010
if (-not $Location) { $MissingParams += "location" }
1111
if (-not $Model) { $MissingParams += "model" }
1212
if (-not $Capacity) { $MissingParams += "capacity" }
13-
if (-not $DeploymentType) { $MissingParams += "deployment-type" }
1413

1514
if ($MissingParams.Count -gt 0) {
1615
Write-Error "❌ ERROR: Missing required parameters: $($MissingParams -join ', ')"
@@ -35,7 +34,7 @@ function Check-Quota {
3534
try {
3635
$ModelInfoRaw = az cognitiveservices usage list --location $Region --query "[?name.value=='$ModelType']" --output json
3736
$ModelInfo = $ModelInfoRaw | ConvertFrom-Json
38-
if (-not $ModelInfo) { return }
37+
if (-not $ModelInfo) { return $null }
3938

4039
$CurrentValue = ($ModelInfo | Where-Object { $_.name.value -eq $ModelType }).currentValue
4140
$Limit = ($ModelInfo | Where-Object { $_.name.value -eq $ModelType }).limit
@@ -52,11 +51,23 @@ function Check-Quota {
5251
Available = $Available
5352
}
5453
} catch {
55-
return
54+
return $null
5655
}
5756
}
5857

59-
# First, check the user-specified region
58+
function Show-Table {
59+
Write-Host "`n-------------------------------------------------------------------------------------------------------------"
60+
Write-Host "| No. | Region | Model Name | Limit | Used | Available |"
61+
Write-Host "-------------------------------------------------------------------------------------------------------------"
62+
$count = 1
63+
foreach ($entry in $AllResults) {
64+
Write-Host ("| {0,-4} | {1,-16} | {2,-35} | {3,-7} | {4,-7} | {5,-9} |" -f $count, $entry.Region, $entry.Model, $entry.Limit, $entry.Used, $entry.Available)
65+
$count++
66+
}
67+
Write-Host "-------------------------------------------------------------------------------------------------------------"
68+
}
69+
70+
# ----------- First check the user-specified region -----------
6071
Write-Host "`n🔍 Checking quota in the requested region '$Location'..."
6172
$PrimaryResult = Check-Quota -Region $Location
6273

@@ -72,45 +83,52 @@ if ($PrimaryResult) {
7283
Write-Host "`n⚠️ Could not retrieve quota info for region '$Location'. Checking fallback regions..."
7384
}
7485

75-
# Remove primary region from fallback list
86+
# ----------- Check all other fallback regions -----------
7687
$FallbackRegions = $PreferredRegions | Where-Object { $_ -ne $Location }
88+
$EligibleFallbacks = @()
7789

7890
foreach ($region in $FallbackRegions) {
7991
$result = Check-Quota -Region $region
8092
if ($result) {
8193
$AllResults += $result
94+
if ($result.Available -ge $Capacity) {
95+
$EligibleFallbacks += $result
96+
}
8297
}
8398
}
8499

85-
# Display Results Table
86-
Write-Host "`n-------------------------------------------------------------------------------------------------------------"
87-
Write-Host "| No. | Region | Model Name | Limit | Used | Available |"
88-
Write-Host "-------------------------------------------------------------------------------------------------------------"
89-
90-
$count = 1
91-
foreach ($entry in $AllResults) {
92-
$modelShort = $entry.Model.Substring($entry.Model.LastIndexOf(".") + 1)
93-
Write-Host ("| {0,-4} | {1,-16} | {2,-35} | {3,-7} | {4,-7} | {5,-9} |" -f $count, $entry.Region, $entry.Model, $entry.Limit, $entry.Used, $entry.Available)
94-
$count++
95-
}
96-
Write-Host "-------------------------------------------------------------------------------------------------------------"
97-
98-
# Suggest fallback regions
99-
$EligibleFallbacks = $AllResults | Where-Object { $_.Region -ne $Location -and $_.Available -ge $Capacity }
100+
# ----------- Show Table of All Regions Checked -----------
101+
Show-Table
100102

103+
# ----------- If eligible fallback regions found, ask user -----------
101104
if ($EligibleFallbacks.Count -gt 0) {
102105
Write-Host "`n❌ Deployment cannot proceed in '$Location'."
103-
Write-Host "➡️ You can retry using one of the following regions with sufficient quota:`n"
104-
foreach ($region in $EligibleFallbacks) {
105-
Write-Host "$($region.Region) (Available: $($region.Available))"
106-
}
106+
Write-Host "➡️ Found fallback regions with sufficient quota."
107+
108+
while ($true) {
109+
Write-Host "`nPlease enter a fallback region from the list above to proceed:"
110+
$NewLocation = Read-Host "Enter region"
111+
112+
if (-not $NewLocation) {
113+
Write-Host "❌ No location entered. Exiting."
114+
exit 1
115+
}
116+
117+
$UserResult = Check-Quota -Region $NewLocation
118+
if (-not $UserResult) {
119+
Write-Host "⚠️ Could not retrieve quota info for region '$NewLocation'. Try again."
120+
continue
121+
}
107122

108-
Write-Host "`n🔧 To proceed, run:"
109-
Write-Host " azd env set AZURE_AISERVICE_LOCATION '<region>'"
110-
Write-Host "📌 To confirm it's set correctly, run:"
111-
Write-Host " azd env get-value AZURE_AISERVICE_LOCATION"
112-
Write-Host "▶️ Once confirmed, re-run azd up to deploy the model in the new region."
113-
exit 2
123+
if ($UserResult.Available -ge $Capacity) {
124+
Write-Host "✅ Sufficient quota found in '$NewLocation'. Proceeding with deployment."
125+
azd env set AZURE_AISERVICE_LOCATION "$NewLocation" | Out-Null
126+
Write-Host "➡️ Set AZURE_AISERVICE_LOCATION to '$NewLocation'."
127+
exit 0
128+
} else {
129+
Write-Host "❌ Insufficient quota in '$NewLocation'. Try another."
130+
}
131+
}
114132
}
115133

116134
Write-Error "`n❌ ERROR: No available quota found in any region."

scripts/validate_model_quota.sh

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ FALLBACK_RESULTS=()
5656
ROW_NO=1
5757

5858
# Print validating message only once
59-
echo -e "\n🔍 Validating model deployment: $MODEL ..."
60-
61-
echo "🔍 Checking quota in the requested region '$LOCATION'..."
59+
echo "🔍 Checking quota in the requested region '$LOCATION' for the Model '$MODEL'..."
6260

6361
# -------------------- Function: Check Quota --------------------
6462
check_quota() {
@@ -129,27 +127,40 @@ if [[ $primary_status -eq 0 ]]; then
129127
exit 0
130128
fi
131129

132-
if [[ ${#FALLBACK_RESULTS[@]} -gt 0 ]]; then
133-
echo -e "\n❌ Deployment cannot proceed in '$LOCATION'."
134-
echo "➡️ You can retry using one of the following regions with sufficient quota:"
135-
echo ""
136-
for region in "${FALLBACK_RESULTS[@]}"; do
137-
for result in "${ALL_RESULTS[@]}"; do
138-
IFS='|' read -r rgn _ _ avail <<< "$result"
139-
if [[ "$rgn" == "$region" ]]; then
140-
echo "$region (Available: $avail)"
141-
break
142-
fi
143-
done
144-
done
145-
146-
echo -e "\n🔧 To proceed, run:"
147-
echo " azd env set AZURE_AISERVICE_LOCATION '<region>'"
148-
echo "📌 To confirm it's set correctly, run:"
149-
echo " azd env get-value AZURE_AISERVICE_LOCATION"
150-
echo "▶️ Once confirmed, re-run azd up to deploy the model in the new region."
151-
exit 2
152-
fi
153130

154-
echo -e "\n❌ ERROR: No available quota found in any region."
155-
exit 1
131+
# Function: Ask user for location and validate quota
132+
ask_for_location() {
133+
echo "Please enter any other location from the above table where you want to deploy AI Services:"
134+
read LOCATION < /dev/tty
135+
136+
# Validate user input
137+
if [[ -z "$LOCATION" ]]; then
138+
echo "❌ ERROR: No location entered. Exiting."
139+
exit 1
140+
fi
141+
142+
echo "🔍 Checking quota in '$LOCATION'..."
143+
check_quota "$LOCATION"
144+
user_region_status=$?
145+
146+
if [[ $user_region_status -eq 0 ]]; then
147+
echo "✅ Sufficient quota found in '$LOCATION'. Proceeding with deployment."
148+
azd env set AZURE_AISERVICE_LOCATION "$LOCATION"
149+
echo "➡️ Set AZURE_AISERVICE_LOCATION to '$LOCATION'."
150+
exit 0
151+
elif [[ $user_region_status -eq 2 ]]; then
152+
echo "⚠️ Could not retrieve quota info for region: '$LOCATION'. Exiting."
153+
exit 1
154+
else
155+
echo "❌ Insufficient quota in '$LOCATION'."
156+
ask_for_location # **Recursively call the function until valid input is provided**
157+
fi
158+
}
159+
160+
# Main Logic
161+
if [[ ${#FALLBACK_RESULTS[@]} -gt 0 ]]; then
162+
echo -e "\n❌ Deployment cannot proceed in this location: '$LOCATION'."
163+
echo "➡️ Found fallback regions with sufficient quota."
164+
165+
ask_for_location # **Call function to prompt user for input**
166+
fi

0 commit comments

Comments
 (0)