-
Notifications
You must be signed in to change notification settings - Fork 2
/
biganimal-csp-preflight
executable file
·676 lines (610 loc) · 21.4 KB
/
biganimal-csp-preflight
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
#!/usr/bin/env bash
#
# Copyright 2021,2022 EnterpriseDB Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This script is used as a preflight check to tell if the given region
# in your Azure subscription can meet the requirement for BigAnimal to create the
# PostgreSQL cluster in.
#
# Given one the below input:
# - (mandatory) Azure subscription ID
# - (mandatory) region
# - PostgreSQL cluster's instance type
# - whether the HA (High Availability) is used for the PostgreSQL cluster
# - whether the EHA (Extreme High Availability) is used for the PostgreSQL cluster
# - network type (private, or public)
# it checks the below requirement:
# - the user is the 'owner' of the Azure subscription
# - the given Azure subscription has the necessary service providers registered
# - the given region:
# * if there is enough SKU(Stock Keeping Unit) left in that region for your PostgreSQL
# cluster's type (of the Virtual Machine)
# * if there is enough Virtual Machine quota left for this PostgreSQL cluster type
# in your Azure subscription
# * if there is enough IP left to expose the service for you to access the
# PostgreSQL cluster
#
# The output of this script tells any unsatisfied condition and report in the form
# of table.
#
# For more details, please refer to:
# https://www.enterprisedb.com/docs/biganimal/latest/getting_started/01_check_resource_limits
#
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
[ "${BASH_VERSINFO:-0}" -lt 4 ] && echo "This script does not support Bash version 3 and below" && show_help && exit 1
NEEDS_QUOTA_INCREASE="false"
function show_help()
{
echo "Usage: $0 [options] <target-subscription> <region>"
echo ""
echo "Arguments:"
echo " <target-subscription> Azure subscription for BigAnimal deployment"
echo " <region> Azure region for BigAnimal deployment"
echo
echo "Options:"
echo " -h, --help Print this help message"
echo " -i, --instance-type Azure VM instance for BigAnimal cluster, e.g., e2s_v3"
echo " -a, --high-availability *DEPRECATED* - Plan for BigAnimal cluster with High Availability enabled"
echo " -x, --cluster-architecture Defines the Cluster architecture and can be [ single | ha | eha ]"
echo " -e, --endpoint Network endpoint flavor for BigAnimal cluster"
echo " -r, --activate-region Include region activation, if no clusters exist in region"
echo " --onboard Check if the user and subscription are configured appropriately"
echo
echo "Behavior defaults to --onboard if no other options provided."
echo
echo "Examples:"
echo " $0 --onboard 12412ab3d-1515-2217-96f5-0338184fcc04 eastus2"
echo " $0 -i e2s_v3 -x single -e private 12412ab3d-1515-2217-96f5-0338184fcc04 eastus2"
echo " $0 -i e2s_v3 -x ha -e private 12412ab3d-1515-2217-96f5-0338184fcc04 eastus2"
echo " $0 -i e2s_v3 -x eha -e private 12412ab3d-1515-2217-96f5-0338184fcc04 eastus2"
echo
echo "Deprecations:"
echo " -a, --high-availability is DEPRECATED, please use -x, --cluster-architecture in its place"
echo
echo "Available regions are: "
echo " ${AVAILABLE_REGIONS[@]}"
echo "Available instance types are: "
echo " ${AVAILABLE_INSTANCETYPE[@]}"
echo "Available endpoint flavors are: "
echo " ${AVAILABLE_ENDPOINTS[@]}"
}
function suggest()
{
local what=$1
local highlight=$2
if [ "$highlight" = 'alert' ]; then
echo -e "${RED}${what}${NC}"
else
echo -e "${GREEN}${what}${NC}"
fi
}
AVAILABLE_ENDPOINTS=(
public
private
)
AVAILABLE_REGIONS=(
australiaeast
brazilsouth
canadacentral
centralindia
centralus
eastus
eastus2
francecentral
germanywestcentral
japaneast
northeurope
norwayeast
southcentralus
southeastasia
uksouth
westeurope
westus2
westus3
)
AVAILABLE_INSTANCETYPE=(
e2s_v3
e4s_v3
e8s_v3
e16s_v3
e20s_v3
e32s_v3
e48s_v3
e64s_v3
e2s_v4
e4s_v4
e8s_v4
e16s_v4
e20s_v4
e32s_v4
e48s_v4
e64s_v4
f4s_v2
f8s_v2
f16s_v2
f32s_v2
f48s_v2
f64s_v2
f72s_v2
d2s_v4
d4s_v4
d8s_v4
d16s_v4
d32s_v4
d48s_v4
d64s_v4
d2s_v3
d4s_v3
d8s_v3
d16s_v3
d32s_v3
d48s_v3
d64s_v3
e2s_v5
e4s_v5
e8s_v5
e16s_v5
e20s_v5
e32s_v5
e48s_v5
e64s_v5
e96s_v5
m8ms
m16ms
m32ms
m64ms
m128ms
)
function _toLower()
{
echo ${1,,}
}
function _toUpper()
{
echo ${1^^}
}
function _extract_instancetype_info()
{
local instance_type=$(_toLower $1)
# extract vcpu/vm_type/vm_family from the given instance_type
local vcpu=0
local serie=""
local psa=""
local version=""
local vm_type=""
local family=""
# given "e20s_v3", the regex pattern is (e)(20)(s)_(v3)
if [[ "${instance_type}" =~ ([a-z]*)([0-9]*)([a-z]*)_(v.*) ]]; then
serie="${BASH_REMATCH[1]}"
vcpu="${BASH_REMATCH[2]}"
psa="${BASH_REMATCH[3]}"
version="${BASH_REMATCH[4]}"
vm_type="Standard_$(_toUpper "$serie")${vcpu}${psa}_${version}"
family="Standard $(_toUpper "$serie")$(_toUpper "${psa}")${version} Family"
# given "m64ms", the regex pattern is (m)(64)(ms)
elif [[ "${instance_type}" =~ ([a-z]*)([0-9]*)([a-z]*) ]]; then
serie="${BASH_REMATCH[1]}"
vcpu="${BASH_REMATCH[2]}"
psa="${BASH_REMATCH[3]}"
vm_type="Standard_$(_toUpper "$serie")${vcpu}${psa}"
family="Standard $(_toUpper "${psa}") Family"
else
echo "Error: unsupported instance type: $1"
exit 1
fi
echo "$vcpu" "$vm_type" "$family"
return 0
}
# Default values for onboarding
endpoint="public"
instance_type="e2s_v3"
ha=false
architecture="single"
activate=false
onboard=false
POSITIONAL=()
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-i|--instance-type)
instance_type="$2"
shift # past argument
shift # past value
;;
-e|--endpoint)
endpoint="$2"
shift # past argument
shift # past value
;;
-a|--high-availability)
ha=true
shift # past argument
;;
-x|--cluster-architecture)
architecture="$2"
shift # past argument
shift # past value
;;
-r|--activate-region)
activate=true
shift # past argument
;;
--onboard)
onboard=true
activate=true
shift # past argument
;;
-h|--help)
show_help
exit 1
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
subscription=$1
region=$2
[ -z "$subscription" ] && show_help && exit 1
[ "$ha" = "true" ] && [ "$architecture" != "single" ] \
&& suggest "You can't pass both HA and cluster-architecture!" alert && show_help && exit 1
[ "$architecture" != "single" ] && [ "$architecture" != "ha" ] && [ "$architecture" != "eha" ] \
&& suggest "cluster-architecture can be only 'single', 'ha' or 'eha'!" alert && show_help && exit 1
# set az cli account to the given subscription to validate it is valid
az account set -s "$subscription"
[ -z "$region" ] && show_help && exit 1
[[ ! " ${AVAILABLE_REGIONS[@]}" =~ "${region}" ]] \
&& echo "error: unsupported region - ${region}" \
&& show_help \
&& exit 1
[[ ! " ${AVAILABLE_INSTANCETYPE[@]}" =~ "${instance_type}" ]] \
&& echo "error: unsupported Postgres instance type - ${instance_type}" \
&& show_help \
&& exit 1
[[ ! " ${AVAILABLE_ENDPOINTS[@]}" =~ "${endpoint}" ]] \
&& echo "error: invalid endpoint flavor - ${endpoint}" \
&& show_help \
&& exit 1
# extract postgres workload used VM instance type info
instance_type_info=($(_extract_instancetype_info "$instance_type"))
pg_vm_vcpu=${instance_type_info[0]}
pg_vm_type=${instance_type_info[1]}
pg_vm_family="${instance_type_info[2]} ${instance_type_info[3]} ${instance_type_info[4]}"
[[ "${pg_vm_type}" = "" ]] \
&& echo "error: unsupported Postgres instance type" \
&& show_help \
&& exit 1
# hardcode management workload used VM instance type info
mgmt_vm_type="Standard_D2_v4"
mgmt_vm_family="Standard Dv4 Family"
# hardcode EHA proxy workload used VM instance type info
eha_proxy_vm_type="Standard_F4s_v2"
eha_proxy_vm_family="Standard FSv2 Family"
eha_proxy_instance_type_info=($(_extract_instancetype_info "$eha_proxy_vm_type"))
pg_eha_proxy_vm_vcpu=${eha_proxy_instance_type_info[0]}
# set the architecture based on parameters architecture and ha (deprecated)
[ "$architecture" = "single" ] && [ "$ha" = "true" ] && architecture="ha"
function infra_vcpus()
{
# 14 are the vCPU required by management VMs
[ "$activate" = "true" ] && echo 14 || echo 0
}
function need_public_ip()
{
[ "$endpoint" = "public" ] && echo 1 || echo 0
}
function need_pg_vcpus_for()
{
local vcpu=$1
local architecture=$2
local replica=1
[ "$architecture" = "ha" ] && replica=3
[ "$architecture" = "eha" ] && replica=3
echo $((vcpu*replica))
}
function need_pg_eha_proxy_vcpus_for()
{
local vcpu=$1
local architecture=$2
local replica=0
[ "$architecture" = "eha" ] && replica=2
echo $((vcpu*replica))
}
# call azure-cli to for usages of VM and Network
TMPDIR=$(mktemp -d)
function _onexit {
#### Print Final Suggestions Result
echo ""
echo "#######################"
echo "# Overall Suggestions #"
echo "#######################"
echo ""
cat "$TMP_SUGGESTION"
echo ""
echo "Please open a ticket to Azure if need to raise quota limit."
echo "Open https://portal.azure.com/#blade/Microsoft_Azure_Support/HelpAndSupportBlade/newsupportrequest for more info."
echo -e "You can also run \033[0;32maz support tickets create --help\033[0m for more examples."
rm -rf "${TMPDIR}"
[ "$NEEDS_QUOTA_INCREASE" == "true" ] && exit 2
exit 0
}
trap _onexit EXIT
pushd "${TMPDIR}" > /dev/null 2>&1 || exit
TMP_VM_OUTPUT=$TMPDIR/vm_$$
TMP_NW_OUTPUT=$TMPDIR/ip_$$
TMP_SKU_OUTPUT=$TMPDIR/sku_$$
TMP_PROVIDER_OUTPUT=$TMPDIR/provider_$$
TMP_SUGGESTION=$TMPDIR/suggestions_$$
touch "$TMP_SUGGESTION"
function store_suggestion()
{
echo "$1" >> "$TMP_SUGGESTION"
}
#### Check Azure CLI version
# refer from
# https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash
vercomp () {
if [[ $1 == $2 ]]
then
return 0
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
return 1
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
return 2
fi
done
return 0
}
function check_az_version {
version=$(az version --query \"azure-cli\" -o tsv)
if command -v clouddrive &> /dev/null; then
echo "Run Azure Preflight Checks with azure-cli ${version} in Azure Cloud shell"
else
set +e
# only support azure-cli >= 2.31.0
vercomp "${version}" 2.31.0
if [ $? -eq 2 ]; then
suggest "Error: this script only supports azure-cli >= 2.31.0" alert
exit 1
fi
# check if we are running azure-cli >= 2.37.0
msgraphapi=true
vercomp "${version}" 2.37.0
if [ $? -eq 2 ]; then
msgraphapi=false
fi
set -e
echo "Run Azure Preflight Checks with azure-cli ${version}"
fi
}
check_az_version
function validate_subscription() {
state=$(echo "$1" | jq -r .state)
if [ "$state" != "Enabled" ]; then
store_suggestion "Azure subscription $subscription state should be Enabled"
fi
tenant_id=$(echo "$account" | jq -r .tenantId)
store_suggestion "Make sure the tenant $tenant_id is the same as the one provided to EDB"
}
#### Azure User Role Assignment Checking
function validate_role_assignment() {
user_name=$(echo "$1" | jq -r .userPrincipalName)
count=$(az role assignment list --assignee "${user_name//\#/%23}" --include-groups --include-inherited --role Owner -o json --only-show-errors 2> /dev/null || echo "{}" | jq length)
if [ "$count" = "0" ]; then
store_suggestion "Current user is $user_name. If you are going to do signup, you should have Owner role of the subscription $subscription"
fi
}
#### Azure User Type Checking
function validate_user_type() {
# The following check starting from Azure CLI 2.37 is skipped due to https://github.com/Azure/azure-cli/issues/22580
# and https://github.com/Azure/azure-cli/issues/22636#issuecomment-1138823356
# until this feature will be delivered into MS Graph APIs
if [ "$msgraphapi" = "false" ]; then
user_type=$(echo "$1" | jq -r .userType)
if [ "$user_type" != "Member" ]; then
store_suggestion "Current user is a $user_type user, not Member user"
fi
fi
}
function check_onboard() {
#### Azure Subscription Checking
account=$(az account show -s "$subscription" -o json)
signed_in_user=$(az ad signed-in-user show -o json --only-show-errors)
validate_subscription "$account"
validate_role_assignment "$signed_in_user"
validate_user_type "$signed_in_user"
}
[ "$onboard" = "true" ] && check_onboard
#### Azure Provider Checking
# Enabled Microsoft.AlertsManagement provider for Failure Anomalies alert rule which is deployed with Application insights autometically
REQUIRED_PROVIDER=(
"Microsoft.Capacity"
"Microsoft.ContainerInstance"
"Microsoft.Compute"
"Microsoft.ContainerService"
"Microsoft.KeyVault"
"Microsoft.ManagedIdentity"
"Microsoft.Network"
"Microsoft.OperationalInsights"
"Microsoft.OperationsManagement"
"Microsoft.Portal"
"Microsoft.Storage"
"Microsoft.AlertsManagement"
)
function provider_suggest()
{
local st=$1
local what=$2
if [ "$st" = "Registered" ]; then
suggest "$st" ok
else
store_suggestion "Provider '$what' is '$st'"
suggest "$st" alert
fi
}
echo ""
echo "#######################"
echo "# Provider #"
echo "#######################"
echo ""
az provider list -o table > "$TMP_PROVIDER_OUTPUT"
# print the provider checking result
FMT="%-40s %-21s %-20b %-s\n"
printf "$FMT" "Namespace" "RegistrationPolicy" "RegistrationState" "ProviderAuthorizationConsentState"
printf "$FMT" "---------------------------------------" "--------------------" "-------------------" "-----------------------------------"
unavail=false
for required_provider in ${REQUIRED_PROVIDER[@]}; do
col=($(< $TMP_PROVIDER_OUTPUT grep -w $required_provider))
provider_namespace=${col[0]}
registration_policy=${col[1]}
registation_state=${col[2]}
provider_authorization_consent_state=${col[3]}
if [[ $registation_state == *"NotRegistered"* ]]; then
unavail=true
fi
printf "$FMT" "$provider_namespace" "$registration_policy" $(provider_suggest "$registation_state" "$required_provider") "$provider_authorization_consent_state"
done
if [ $unavail = "true" ]; then
store_suggestion "Register all required providers before continue"
cat "$TMP_SUGGESTION"
exit 1
fi
function get_sku_zone_for()
{
local what=$1
awk "/ $what /" "$TMP_SKU_OUTPUT" | awk '{print $4}'
}
function get_sku_restriction_for()
{
local what=$1
awk "/ $what /" "$TMP_SKU_OUTPUT" | awk '{$1=$2=$3=$4=""; print $0}' | xargs
}
function sku_suggest()
{
local restriction=$1
local sku=$2
if [ "$restriction" = "None" ] || ([[ $restriction == *"type: Zone"* ]] && [ "$sku" = "$mgmt_vm_type" ]); then
suggest "None" ok
else
store_suggestion "virtualMachines SKU '$sku' has '$restriction'"
suggest "$restriction" alert
fi
}
echo ""
echo "#######################"
echo "# Virtual-Machine SKU #"
echo "#######################"
echo ""
vmsku_mgmt=$mgmt_vm_type
vmsku_pg=$pg_vm_type
[ "$architecture" = "eha" ] && vmsku_eha_proxy=$eha_proxy_vm_type
az vm list-skus -l "$region" --all -o table > "$TMP_SKU_OUTPUT"
sku_restriction_mgmt=$(get_sku_restriction_for "${vmsku_mgmt}")
sku_restriction_pg=$(get_sku_restriction_for "${vmsku_pg}")
[ "$architecture" = "eha" ] && sku_restriction_eha_proxy=$(get_sku_restriction_for "${vmsku_eha_proxy}")
# print region Azure VM SKU checking result
FMT="%-17s %-22s %-23s %-8s %-b\n"
printf "$FMT" "ResourceType" "Regions" "Name" "Zones" "Restrictions"
printf "$FMT" "------------" "---------" "----" "-----" "------------"
printf "$FMT" "virtualMachines" "$region" "${vmsku_mgmt}" "$(get_sku_zone_for "${vmsku_mgmt}")" "$(sku_suggest "$sku_restriction_mgmt" "${vmsku_mgmt}")"
printf "$FMT" "virtualMachines" "$region" "${vmsku_pg}" "$(get_sku_zone_for "${vmsku_pg}")" "$(sku_suggest "$sku_restriction_pg" "${vmsku_pg}")"
[ "$architecture" = "eha" ] && printf "$FMT" "virtualMachines" "$region" "${vmsku_eha_proxy}" "$(get_sku_zone_for "${vmsku_eha_proxy}")" "$(sku_suggest "$sku_restriction_eha_proxy" "${vmsku_eha_proxy}")"
echo ""
echo "#######################"
echo "# Quota Limitation #"
echo "#######################"
echo ""
az vm list-usage -l "$region" -o table > "$TMP_VM_OUTPUT"
# parse VM usage
function get_vm_usage_for()
{
local what=$1
< "$TMP_VM_OUTPUT" grep "${what}" | awk '{print $(NF-1)" "$NF}'
}
regional_vcpus=($(get_vm_usage_for "Total Regional vCPUs"))
mgmt_vcpus=($(get_vm_usage_for "$mgmt_vm_family vCPUs"))
pg_vcpus=($(get_vm_usage_for "$pg_vm_family vCPUs"))
pg_eha_proxy_vcpus=($(get_vm_usage_for "$eha_proxy_vm_family vCPUs"))
# parse network usage
publicip_standard=($(az network list-usages -l "$region" -o json | jq -r '.[] | select(.name.value == "StandardSkuPublicIpAddresses") | [.currentValue,.limit] | join(" ")'))
# calculate available resources
free_regional_vcpus=$((${regional_vcpus[1]} - ${regional_vcpus[0]}))
free_mgmt_vcpus=$((${mgmt_vcpus[1]} - ${mgmt_vcpus[0]}))
free_pg_vcpus=$((${pg_vcpus[1]} - ${pg_vcpus[0]}))
free_pg_eha_proxy_vcpus=$((${pg_eha_proxy_vcpus[1]} - ${pg_eha_proxy_vcpus[0]}))
free_publicip_standard=$((${publicip_standard[1]} - ${publicip_standard[0]}))
# calculate required resources
need_mgmt_vcpus=$(infra_vcpus)
need_pg_vcpus=$(need_pg_vcpus_for "$pg_vm_vcpu" "$architecture")
need_pg_eha_proxy_vcpus=$(need_pg_eha_proxy_vcpus_for "$pg_eha_proxy_vm_vcpu" "$architecture")
need_regional_vcpus=$((need_mgmt_vcpus + need_pg_vcpus + need_pg_eha_proxy_vcpus))
need_publicip_standard=$(need_public_ip)
shared_mgmt_eha_proxy_vcpus=0
if [ "$mgmt_vm_family" = "$eha_proxy_vm_family" ]; then
shared_mgmt_eha_proxy_vcpus=$((need_mgmt_vcpus + need_pg_eha_proxy_vcpus))
fi
# calculate gap of "need - free"
gap_mgmt_vcpus=$((free_mgmt_vcpus - (shared_mgmt_eha_proxy_vcpus > need_mgmt_vcpus ? shared_mgmt_eha_proxy_vcpus : need_mgmt_vcpus) ))
gap_pg_vcpus=$((free_pg_vcpus - need_pg_vcpus))
gap_pg_eha_proxy_vcpus=$((free_pg_eha_proxy_vcpus - (shared_mgmt_eha_proxy_vcpus > need_pg_eha_proxy_vcpus ? shared_mgmt_eha_proxy_vcpus : need_pg_eha_proxy_vcpus) ))
gap_regional_vcpus=$((free_regional_vcpus - need_regional_vcpus))
gap_publicip_standard=$((free_publicip_standard - need_publicip_standard))
function quota_suggest()
{
local gap=$1
local resource=$2
if [ "$gap" -lt 0 ]; then
store_suggestion "Resource '$resource' quota in '$region' has a gap of '$gap'"
suggest "Increase Quota by ${gap:1}" alert
else
suggest "OK" ok
fi
}
# print region resources quota limitation checking result
FMT="%-32s %-8s %-8s %-11s %-11s %-8s %-11b\n"
printf "$FMT" "Resource" "Limit" "Used" "Available" "Required" "Gap" "Suggestion"
printf "$FMT" "--------" "-----" "----" "---------" "--------" "---" "----------"
printf "$FMT" "Total Regional vCPUs" ${regional_vcpus[1]} ${regional_vcpus[0]} ${free_regional_vcpus} $need_regional_vcpus $gap_regional_vcpus "$(quota_suggest $gap_regional_vcpus "Total Regional vCPUs")"
[ "$shared_mgmt_eha_proxy_vcpus" -gt 0 ] && need_mgmt_vcpus=$((need_mgmt_vcpus + need_pg_eha_proxy_vcpus))
printf "$FMT" "$mgmt_vm_family vCPUs" ${mgmt_vcpus[1]} ${mgmt_vcpus[0]} ${free_mgmt_vcpus} ${need_mgmt_vcpus} ${gap_mgmt_vcpus} "$(quota_suggest $gap_mgmt_vcpus "$mgmt_vm_family vCPUs")"
printf "$FMT" "$pg_vm_family vCPUs" ${pg_vcpus[1]} ${pg_vcpus[0]} ${free_pg_vcpus} ${need_pg_vcpus} ${gap_pg_vcpus} "$(quota_suggest $gap_pg_vcpus "$pg_vm_family vCPUs")"
[ "$shared_mgmt_eha_proxy_vcpus" -eq 0 ] && [ "$need_pg_eha_proxy_vcpus" -gt 0 ] && \
printf "$FMT" "$eha_proxy_vm_family vCPUs" ${pg_eha_proxy_vcpus[1]} ${pg_eha_proxy_vcpus[0]} ${free_pg_eha_proxy_vcpus} ${need_pg_eha_proxy_vcpus} ${gap_pg_eha_proxy_vcpus} "$(quota_suggest $gap_pg_eha_proxy_vcpus "$eha_proxy_vm_family vCPUs")"
printf "$FMT" "Public IP Addresses - Standard" ${publicip_standard[1]} ${publicip_standard[0]} ${free_publicip_standard} ${need_publicip_standard} ${gap_publicip_standard} "$(quota_suggest $gap_publicip_standard "Public IP Addresses - Standard")"
if [ "${gap_regional_vcpus}" -lt 0 ] || [ "${gap_mgmt_vcpus}" -lt 0 ] || [ "${gap_pg_vcpus}" -lt 0 ] || [ "${gap_pg_eha_proxy_vcpus}" -lt 0 ] || [ "${gap_publicip_standard}" -lt 0 ]; then
NEEDS_QUOTA_INCREASE="true"
fi