Skip to content

Commit 59a4d7f

Browse files
updated the script as per suggestion
1 parent 40cb4e8 commit 59a4d7f

4 files changed

Lines changed: 49 additions & 3 deletions

File tree

scripts/validate_model_deployment_quota.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ if ($MissingParams.Count -gt 0) {
1919
exit 1
2020
}
2121

22+
# Check Azure login
23+
try {
24+
$accountCheck = az account show --output none 2>$null
25+
if ($LASTEXITCODE -ne 0) {
26+
Write-Error "❌ ERROR: You are not logged in to Azure CLI. Please run 'az login' to continue."
27+
exit 1
28+
}
29+
} catch {
30+
Write-Error "❌ ERROR: Failed to verify Azure login. Please run 'az login' to continue."
31+
exit 1
32+
}
33+
2234
# Load model deployments from parameter file
2335
$JsonContent = Get-Content -Path "./infra/main.parameters.json" -Raw | ConvertFrom-Json
2436
$aiModelDeployments = $JsonContent.parameters.$ModelsParameter.value

scripts/validate_model_deployment_quota.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ if [[ ${#MISSING_PARAMS[@]} -ne 0 ]]; then
4040
exit 1
4141
fi
4242

43+
# Check if user is logged in to Azure
44+
if ! az account show > /dev/null 2>&1; then
45+
echo "❌ ERROR: You are not logged in to Azure CLI."
46+
echo "👉 Please run 'az login' to continue."
47+
exit 1
48+
fi
49+
4350
# Load model definitions
4451
aiModelDeployments=$(jq -c ".parameters.$MODELS_PARAMETER.value[]" ./infra/main.parameters.json 2>/dev/null)
4552
if [[ $? -ne 0 || -z "$aiModelDeployments" ]]; then

scripts/validate_model_quota.ps1

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,13 @@ if ($PrimaryResult) {
111111
Write-Host "🚨 Your application may not work as expected due to limited quota."
112112
Write-Host "`nℹ️ Recommended regions: $($RecommendedRegions -join ', ')"
113113
Write-Host "👉 It's advisable to deploy in one of these regions for optimal app performance."
114-
$choice = Read-Host "❓ Do you want to choose a recommended region instead? (y/n)"
114+
do {
115+
$choice = Read-Host "❓ Do you want to choose a recommended region instead? (y/n)"
116+
if ($choice -notmatch "^[YyNn]$") {
117+
Write-Host "❌ Invalid input. Please enter 'y' or 'n'."
118+
}
119+
} while ($choice -notmatch "^[YyNn]$")
120+
115121
if ($choice -match "^[Yy]$") {
116122
Show-Table
117123
break
@@ -186,7 +192,13 @@ while ($true) {
186192
Write-Host "`n⚠️ You have entered a capacity of $ManualCapacity, which is less than the recommended minimum (200)."
187193
Write-Host "🚨 This may cause performance issues or unexpected behavior."
188194
Write-Host "ℹ️ Recommended regions (≥ $RECOMMENDED_TOKENS tokens available): $($RecommendedRegions -join ', ')"
189-
$proceed = Read-Host "❓ Proceed anyway? (y/n)"
195+
do {
196+
$proceed = Read-Host "❓ Proceed anyway? (y/n)"
197+
if ($proceed -notmatch "^[YyNn]$") {
198+
Write-Host "❌ Invalid input. Please enter 'y' or 'n'."
199+
}
200+
} while ($proceed -notmatch "^[YyNn]$")
201+
190202
if ($proceed -notmatch "^[Yy]$") {
191203
continue
192204
}

scripts/validate_model_quota.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ MODEL=""
55
DEPLOYMENT_TYPE="Standard"
66
CAPACITY=0
77
RECOMMENDED_TOKENS=200
8+
TABLE_SHOWN=false
89

910
ALL_REGIONS=('australiaeast' 'eastus' 'eastus2' 'francecentral' 'japaneast' 'norwayeast' 'southindia' 'swedencentral' 'uksouth' 'westus' 'westus3')
1011

@@ -44,6 +45,9 @@ check_quota() {
4445
output=$(az cognitiveservices usage list --location "$region" --query "[?name.value=='$MODEL_TYPE']" --output json 2>/dev/null)
4546

4647
if [[ -z "$output" || "$output" == "[]" ]]; then
48+
if [[ "$region" == "$LOCATION" ]]; then
49+
echo "⚠️ Could not retrieve the quota info for the region: $LOCATION"
50+
fi
4751
return 2
4852
fi
4953

@@ -107,6 +111,10 @@ ask_for_location() {
107111
echo -e "ℹ️ Recommended regions (≥ $RECOMMENDED_TOKENS tokens available): $recommended_list"
108112
echo -n "❓ Proceed anyway? (y/n): "
109113
read -r proceed_anyway < /dev/tty
114+
while [[ ! "$proceed_anyway" =~ ^[YyNn]$ ]]; do
115+
echo "❌ Invalid input. Please enter 'y' or 'n': "
116+
read -r proceed_anyway < /dev/tty
117+
done
110118
if [[ ! "$proceed_anyway" =~ ^[Yy]$ ]]; then
111119
ask_for_location
112120
return
@@ -138,7 +146,10 @@ check_fallback_regions() {
138146
fi
139147
done
140148

141-
show_table
149+
if [[ "$TABLE_SHOWN" == false ]]; then
150+
show_table
151+
TABLE_SHOWN=true
152+
fi
142153

143154
if [[ ${#FALLBACK_RESULTS[@]} -gt 0 ]]; then
144155
echo -e "\n➡️ Found fallback regions with sufficient quota."
@@ -189,6 +200,10 @@ manual_region_input() {
189200
echo -e "ℹ️ Recommended regions (≥ $RECOMMENDED_TOKENS tokens available): ${RECOMMENDED_REGIONS[*]}"
190201
echo -n "❓ Proceed anyway? (y/n): "
191202
read -r proceed_anyway < /dev/tty
203+
while [[ ! "$proceed_anyway" =~ ^[YyNn]$ ]]; do
204+
echo "❌ Invalid input. Please enter 'y' or 'n': "
205+
read -r proceed_anyway < /dev/tty
206+
done
192207
if [[ ! "$proceed_anyway" =~ ^[Yy]$ ]]; then
193208
manual_region_input
194209
return

0 commit comments

Comments
 (0)