Skip to content

Commit 70af70e

Browse files
Rename quota_check.sh to checkquota.sh
1 parent 79cefa3 commit 70af70e

2 files changed

Lines changed: 96 additions & 245 deletions

File tree

scripts/checkquota.sh

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/bin/bash
2+
3+
# List of Azure regions to check for quota (update as needed)
4+
IFS=', ' read -ra REGIONS <<< "$AZURE_REGIONS"
5+
6+
SUBSCRIPTION_ID="${AZURE_SUBSCRIPTION_ID}"
7+
GPT_MIN_CAPACITY="${GPT_MIN_CAPACITY}"
8+
AZURE_CLIENT_ID="${AZURE_CLIENT_ID}"
9+
AZURE_TENANT_ID="${AZURE_TENANT_ID}"
10+
AZURE_CLIENT_SECRET="${AZURE_CLIENT_SECRET}"
11+
12+
# Authenticate using Managed Identity
13+
echo "Authentication using Managed Identity..."
14+
if ! az login --service-principal -u "$AZURE_CLIENT_ID" -p "$AZURE_CLIENT_SECRET" --tenant "$AZURE_TENANT_ID"; then
15+
echo "❌ Error: Failed to login using Managed Identity."
16+
exit 1
17+
fi
18+
19+
echo "🔄 Validating required environment variables..."
20+
if [[ -z "$SUBSCRIPTION_ID" || -z "$GPT_MIN_CAPACITY" || -z "$REGIONS" ]]; then
21+
echo "❌ ERROR: Missing required environment variables."
22+
exit 1
23+
fi
24+
25+
echo "🔄 Setting Azure subscription..."
26+
if ! az account set --subscription "$SUBSCRIPTION_ID"; then
27+
echo "❌ ERROR: Invalid subscription ID or insufficient permissions."
28+
exit 1
29+
fi
30+
echo "✅ Azure subscription set successfully."
31+
32+
# Define models and their minimum required capacities
33+
declare -A MIN_CAPACITY=(
34+
["OpenAI.GlobalStandard.gpt-4o"]=$GPT_MIN_CAPACITY
35+
)
36+
37+
VALID_REGION=""
38+
for REGION in "${REGIONS[@]}"; do
39+
echo "----------------------------------------"
40+
echo "🔍 Checking region: $REGION"
41+
42+
QUOTA_INFO=$(az cognitiveservices usage list --location "$REGION" --output json)
43+
if [ -z "$QUOTA_INFO" ]; then
44+
echo "⚠️ WARNING: Failed to retrieve quota for region $REGION. Skipping."
45+
continue
46+
fi
47+
48+
INSUFFICIENT_QUOTA=false
49+
for MODEL in "${!MIN_CAPACITY[@]}"; do
50+
MODEL_INFO=$(echo "$QUOTA_INFO" | awk -v model="\"value\": \"$MODEL\"" '
51+
BEGIN { RS="},"; FS="," }
52+
$0 ~ model { print $0 }
53+
')
54+
55+
if [ -z "$MODEL_INFO" ]; then
56+
echo "⚠️ WARNING: No quota information found for model: $MODEL in $REGION. Skipping."
57+
INSUFFICIENT_QUOTA=true
58+
continue
59+
fi
60+
61+
CURRENT_VALUE=$(echo "$MODEL_INFO" | awk -F': ' '/"currentValue"/ {print $2}' | tr -d ',' | tr -d ' ')
62+
LIMIT=$(echo "$MODEL_INFO" | awk -F': ' '/"limit"/ {print $2}' | tr -d ',' | tr -d ' ')
63+
64+
CURRENT_VALUE=${CURRENT_VALUE:-0}
65+
LIMIT=${LIMIT:-0}
66+
67+
CURRENT_VALUE=$(echo "$CURRENT_VALUE" | cut -d'.' -f1)
68+
LIMIT=$(echo "$LIMIT" | cut -d'.' -f1)
69+
70+
AVAILABLE=$((LIMIT - CURRENT_VALUE))
71+
72+
echo "✅ Model: $MODEL | Used: $CURRENT_VALUE | Limit: $LIMIT | Available: $AVAILABLE"
73+
74+
if [ "$AVAILABLE" -lt "${MIN_CAPACITY[$MODEL]}" ]; then
75+
echo "❌ ERROR: $MODEL in $REGION has insufficient quota."
76+
INSUFFICIENT_QUOTA=true
77+
break
78+
fi
79+
done
80+
81+
if [ "$INSUFFICIENT_QUOTA" = false ]; then
82+
VALID_REGION="$REGION"
83+
break
84+
fi
85+
86+
done
87+
88+
if [ -z "$VALID_REGION" ]; then
89+
echo "❌ No region with sufficient quota found. Blocking deployment."
90+
echo "QUOTA_FAILED=true" >> "$GITHUB_ENV"
91+
exit 0
92+
else
93+
echo "✅ Final Region: $VALID_REGION"
94+
echo "VALID_REGION=$VALID_REGION" >> "$GITHUB_ENV"
95+
exit 0
96+
fi

scripts/quota_check.sh

Lines changed: 0 additions & 245 deletions
This file was deleted.

0 commit comments

Comments
 (0)