Skip to content

Commit 0afb31d

Browse files
updated powershell similar to shell script
1 parent 4ea4e89 commit 0afb31d

1 file changed

Lines changed: 32 additions & 54 deletions

File tree

scripts/validate_model_quota.ps1

Lines changed: 32 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ function Set-DeploymentValues($Region, $Capacity) {
109109

110110
function Manual-Prompt {
111111
while ($true) {
112-
$ManualRegion = Read-Host "`nPlease enter a region you want to try manually"
112+
Write-Host "`n📍 Recommended regions (≥ $RECOMMENDED_TOKENS tokens available): $($RecommendedRegions -join ', ')"
113+
$ManualRegion = Read-Host "Please enter a region you want to try manually"
113114
if (-not $ManualRegion) {
114115
Write-Host "❌ ERROR: No region entered. Exiting."
115116
exit 1
@@ -151,80 +152,57 @@ function Manual-Prompt {
151152
}
152153
}
153154

154-
# Start validation and execution
155+
# Start validation and quota checks
155156
Validate-Inputs
156157

157158
Write-Host "`n🔍 Checking quota in the requested region '$Location'..."
158159
$PrimaryResult = Check-Quota -Region $Location
159-
160160
if ($PrimaryResult) {
161-
$AllResults += $PrimaryResult
162-
if ($PrimaryResult.Available -ge $Capacity) {
163-
if ($RecommendedRegions -notcontains $Location -and $RecommendedRegions.Count -gt 0) {
164-
Write-Host "`n⚠️ Selected region '$Location' has sufficient quota but is not among the recommended regions (≥ $RECOMMENDED_TOKENS tokens)."
165-
Write-Host "🚨 Your application may not work as expected due to limited quota."
166-
Write-Host "`nℹ️ Recommended regions: $($RecommendedRegions -join ', ')"
167-
if (Confirm-Action "❓ Do you want to choose a recommended region instead?") {
168-
Show-Table
169-
exit 0
170-
} else {
171-
if ($Capacity -gt $RECOMMENDED_TOKENS) {
172-
Write-Host "`n⚠️ Reducing capacity to $RECOMMENDED_TOKENS in '$BicepParamsFile' for safer deployment..."
173-
(Get-Content $BicepParamsFile) -replace "capacity\s*:\s*\d+", "capacity: $RECOMMENDED_TOKENS" | Set-Content $BicepParamsFile
174-
Write-Host "✅ Updated '$BicepParamsFile' with capacity $RECOMMENDED_TOKENS."
175-
}
176-
Set-DeploymentValues $Location $Capacity
177-
Write-Host "✅ Proceeding with '$Location' as selected."
178-
exit 0
179-
}
180-
} else {
181-
Write-Host "`n✅ Sufficient quota found in original region '$Location'."
182-
if ($PrimaryResult.Available -lt $RECOMMENDED_TOKENS) {
183-
Write-Host "`n⚠️ You have provided a capacity of $Capacity, which is less than the recommended minimum ($RECOMMENDED_TOKENS)."
184-
Write-Host "🚨 This may cause performance issues or unexpected behavior."
185-
if ($RecommendedRegions.Count -gt 0) {
186-
Write-Host "ℹ️ Recommended regions (≥ $RECOMMENDED_TOKENS tokens available): $($RecommendedRegions -join ', ')"
187-
}
188-
if (-not (Confirm-Action "❓ Proceed anyway?")) {
189-
Write-Host "❌ Deployment aborted by user. Please select another region or capacity."
190-
exit 1
191-
}
192-
}
193-
Set-DeploymentValues $Location $Capacity
194-
exit 0
195-
}
196-
} else {
197-
Write-Host "`n⚠️ Insufficient quota in '$Location' (Available: $($PrimaryResult.Available), Required: $Capacity). Checking fallback regions..."
198-
}
199-
} else {
200-
Write-Host "`n⚠️ Could not retrieve quota info for region '$Location'."
161+
$AllResults = @($AllResults) + $PrimaryResult
201162
}
202163

203164
foreach ($region in $PreferredRegions) {
204-
if ($region -eq $Location) { continue }
205-
$result = Check-Quota -Region $region
206-
if ($result) {
207-
$AllResults += $result
208-
if ($result.Available -ge $Capacity) {
209-
$EligibleFallbacks += $region
165+
if ($region -ne $Location) {
166+
$fallbackResult = Check-Quota -Region $region
167+
if ($fallbackResult) {
168+
$AllResults = @($AllResults) + $fallbackResult
169+
if ($fallbackResult.Available -ge $Capacity) {
170+
$EligibleFallbacks += $region
171+
}
210172
}
211173
}
212174
}
213175

214176
Show-Table
215177

216-
if ($EligibleFallbacks.Count -gt 0) {
217-
Write-Host "`n➡️ Found fallback regions with sufficient quota."
178+
if ($Capacity -lt $RECOMMENDED_TOKENS) {
179+
Write-Host "`n⚠️ You have entered a capacity of $Capacity, which is less than the recommended minimum ($RECOMMENDED_TOKENS)."
180+
Write-Host "🚨 This may cause performance issues or unexpected behavior."
181+
Write-Host "ℹ️ Recommended regions (≥ $RECOMMENDED_TOKENS tokens available):"
218182
if ($RecommendedRegions.Count -gt 0) {
219-
Write-Host "`nℹ️ Recommended regions (≥ $RECOMMENDED_TOKENS tokens available):"
220183
foreach ($region in $RecommendedRegions) {
221184
Write-Host " - $region"
222185
}
186+
} else {
187+
Write-Host " ❌ No recommended regions currently available."
223188
}
224-
Write-Host "`n❗ The originally selected region '$Location' does not have enough quota."
189+
if (-not (Confirm-Action "❓ Proceed anyway?")) {
190+
Manual-Prompt
191+
exit 0
192+
}
193+
}
194+
195+
if ($PrimaryResult -and $PrimaryResult.Available -ge $Capacity) {
196+
Set-DeploymentValues $Location $Capacity
197+
Write-Host "✅ Proceeding with '$Location' as selected."
198+
exit 0
199+
}
200+
201+
Write-Host "`n❗ The originally selected region '$Location' does not have enough quota."
202+
if ($EligibleFallbacks.Count -gt 0) {
225203
Write-Host "👉 You can manually choose one of the recommended fallback regions for deployment."
226204
} else {
227-
Write-Host "`n❌ ERROR: No region has sufficient quota."
205+
Write-Host "❌ ERROR: No region has sufficient quota."
228206
}
229207

230208
Manual-Prompt

0 commit comments

Comments
 (0)