@@ -7,7 +7,7 @@ CAPACITY=0
77RECOMMENDED_TOKENS=200
88TABLE_SHOWN=false
99RECOMMENDATIONS_SHOWN=false
10- INITIAL_LOCATION=" " # NEW: track the original region
10+ INITIAL_LOCATION=" "
1111
1212ALL_REGIONS=(' australiaeast' ' eastus' ' eastus2' ' francecentral' ' japaneast' ' norwayeast' ' southindia' ' swedencentral' ' uksouth' ' westus' ' westus3' )
1313
@@ -16,8 +16,6 @@ NOT_RECOMMENDED_REGIONS=()
1616ALL_RESULTS=()
1717FALLBACK_RESULTS=()
1818
19- # ---------- Helper Functions ----------
20-
2119prompt_yes_no () {
2220 local prompt=" $1 "
2321 local response
@@ -32,14 +30,28 @@ prompt_yes_no() {
3230
3331print_recommended_warning () {
3432 local capacity=" $1 "
35- local recommended_list
36- recommended_list=$( IFS=, ; echo " ${RECOMMENDED_REGIONS[*]} " )
37- primary_entry=" ${ALL_RESULTS[0]} "
38- IFS=' |' read -r _ limit used available <<< " $primary_entry"
39- echo -e " \n⚠️ You have entered a capacity of $capacity , which is less than the recommended minimum ($RECOMMENDED_TOKENS )."
40- echo -e " 🚨 This may cause performance issues or unexpected behavior."
41- echo -e " 📊 Available quota in '$LOCATION ': $available , Required: $capacity "
42- if [[ -n " $recommended_list " ]]; then
33+ local matched_entry=" "
34+
35+ for entry in " ${ALL_RESULTS[@]} " ; do
36+ IFS=' |' read -r region _ _ _ <<< " $entry"
37+ if [[ " $region " == " $LOCATION " ]]; then
38+ matched_entry=" $entry "
39+ break
40+ fi
41+ done
42+
43+ if [[ -n " $matched_entry " ]]; then
44+ IFS=' |' read -r _ limit used available <<< " $matched_entry"
45+ echo -e " \n⚠️ You have entered a capacity of $capacity , which is less than the recommended minimum ($RECOMMENDED_TOKENS )."
46+ echo -e " 🚨 This may cause performance issues or unexpected behavior."
47+ echo -e " 📊 Available quota in '$LOCATION ': $available , Required: $capacity "
48+ else
49+ echo -e " \n⚠️ Capacity entered is below recommended, but region quota data was not found."
50+ fi
51+
52+ if [[ ${# RECOMMENDED_REGIONS[@]} -gt 0 ]]; then
53+ local recommended_list
54+ recommended_list=$( IFS=, ; echo " ${RECOMMENDED_REGIONS[*]} " )
4355 echo -e " ℹ️ Recommended regions (≥ $RECOMMENDED_TOKENS tokens available): $recommended_list "
4456 fi
4557}
@@ -125,30 +137,31 @@ ask_for_location() {
125137 return
126138 fi
127139
128- if (( new_capacity < RECOMMENDED_TOKENS )) ; then
129- print_recommended_warning " $new_capacity "
130- prompt_yes_no " ❓ Proceed anyway? (y/n): " || { ask_for_location; return ; }
131- fi
140+ LOCATION=" $new_location "
141+ CAPACITY=" $new_capacity "
132142
133- echo -e " \n🔍 Checking quota in region ' $new_location ' for requested capacity: $new_capacity ... "
134- CAPACITY= $new_capacity
135- LOCATION= $new_location
143+ update_env_and_parameters " $LOCATION " " $CAPACITY "
144+
145+ echo -e " \n🔍 Checking quota in region ' $ LOCATION' for requested capacity: $CAPACITY ... "
136146
137147 if check_quota " $LOCATION " ; then
138148 if (( CAPACITY < RECOMMENDED_TOKENS )) ; then
139149 print_recommended_warning " $CAPACITY "
140- prompt_yes_no " ❓ Proceed anyway? (y/n): " || { ask_for_location; exit 0; }
150+ prompt_yes_no " ❓ Proceed anyway? (y/n): " || {
151+ ask_for_location
152+ return
153+ }
141154 fi
142- update_env_and_parameters " $LOCATION " " $CAPACITY "
155+ # update_env_and_parameters "$LOCATION" "$CAPACITY"
143156 echo " ✅ Proceeding with deployment in '$LOCATION '."
144157 exit 0
145158 else
146- check_fallback_regions false
159+ echo " ❌ Quota insufficient in '$LOCATION '. Checking fallback regions..."
160+ check_fallback_regions
147161 fi
148162}
149163
150164check_fallback_regions () {
151- local is_first_check=" ${1:- true} "
152165 for region in " ${ALL_REGIONS[@]} " ; do
153166 [[ " $region " == " $LOCATION " ]] && continue
154167 check_quota " $region " && FALLBACK_RESULTS+=(" $region " )
@@ -167,15 +180,7 @@ check_fallback_regions() {
167180 echo " - $region "
168181 done
169182 fi
170- RECOMMENDATIONS_SHOWN=true
171- if [[ " $is_first_check " == true ]]; then
172- echo -e " \n❗ The originally selected region '$INITIAL_LOCATION ' does not have enough quota."
173- else
174- echo -e " \n⚠️ Region '$LOCATION ' does not have enough quota."
175- RECOMMENDATIONS_SHOWN=false
176- fi
177183 echo -e " 👉 You can manually choose one of the recommended fallback regions for deployment."
178-
179184 else
180185 echo -e " \n❌ ERROR: No region has sufficient quota."
181186 fi
@@ -205,12 +210,12 @@ if [[ -z "$LOCATION" || -z "$MODEL" || -z "$CAPACITY" || "$CAPACITY" -le 0 ]]; t
205210fi
206211
207212# ---------- Start Process ----------
208- INITIAL_LOCATION=" $LOCATION " # Set initial region
213+ INITIAL_LOCATION=" $LOCATION "
209214
210215echo -e " \n🔍 Checking quota in the requested region '$LOCATION '..."
211216if check_quota " $LOCATION " ; then
212217 if (( CAPACITY < RECOMMENDED_TOKENS )) ; then
213- check_fallback_regions true
218+ check_fallback_regions
214219 print_recommended_warning " $CAPACITY "
215220 prompt_yes_no " ❓ Proceed anyway? (y/n): " || {
216221 ask_for_location
224229 primary_entry=" ${ALL_RESULTS[0]} "
225230 IFS=' |' read -r _ limit used available <<< " $primary_entry"
226231 echo " ❌ Quota insufficient in '$LOCATION ' (Available: $available , Required: $CAPACITY ). Checking fallback regions..."
227- check_fallback_regions true
232+ check_fallback_regions
228233fi
0 commit comments