@@ -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,-3} | {1,-14} | {2,-35} | {3,-5} | {4,-5} | {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,53 @@ 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+ $AllResults = $AllResults | Where-Object { $_.Available -gt 50 }
102+ Show-Table
100103
104+ # ----------- If eligible fallback regions found, ask user -----------
101105if ($EligibleFallbacks.Count -gt 0 ) {
102106 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- }
107+ Write-Host " ➡️ Found fallback regions with sufficient quota."
108+
109+ while ($true ) {
110+ Write-Host " `n Please enter a fallback region from the list above to proceed:"
111+ $NewLocation = Read-Host " Enter region"
112+
113+ if (-not $NewLocation ) {
114+ Write-Host " ❌ No location entered. Exiting."
115+ exit 1
116+ }
117+
118+ $UserResult = Check- Quota - Region $NewLocation
119+ if (-not $UserResult ) {
120+ Write-Host " ⚠️ Could not retrieve quota info for region '$NewLocation '. Try again."
121+ continue
122+ }
107123
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
124+ if ($UserResult.Available -ge $Capacity ) {
125+ Write-Host " ✅ Sufficient quota found in '$NewLocation '. Proceeding with deployment."
126+ azd env set AZURE_AISERVICE_LOCATION " $NewLocation " | Out-Null
127+ Write-Host " ➡️ Set AZURE_AISERVICE_LOCATION to '$NewLocation '."
128+ exit 0
129+ } else {
130+ Write-Host " ❌ Insufficient quota in '$NewLocation '. Try another."
131+ }
132+ }
114133}
115134
116135Write-Error " `n ❌ ERROR: No available quota found in any region."
0 commit comments