@@ -10,7 +10,6 @@ $MissingParams = @()
1010if (-not $Location ) { $MissingParams += " location" }
1111if (-not $Model ) { $MissingParams += " model" }
1212if (-not $Capacity ) { $MissingParams += " capacity" }
13- if (-not $DeploymentType ) { $MissingParams += " deployment-type" }
1413
1514if ($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 -----------
6071Write-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
7890foreach ($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 -----------
101104if ($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 " `n Please 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
116134Write-Error " `n ❌ ERROR: No available quota found in any region."
0 commit comments