-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcp-convenience-methods.sh
45 lines (36 loc) · 1.05 KB
/
gcp-convenience-methods.sh
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
#!/bin/bash
function get-project-number() {
project="$1"
gcloud --project=$project projects \
describe $project \
--format='get(projectNumber)'
}
function get-region-of-mig () {
project="$1"
mig_name="$2"
gcloud --project="$project" \
compute instance-groups list \
--filter="name = '$mig_name'" |\
awk -v name="$mig_name" '$1 == name { print $2 }'
}
function get-all-instances () {
project="$1"
mig="$2"
region=$(get-region-of-mig $project $mig)
gcloud --project="$project" \
compute instance-groups managed list-instances \
--region="$region" \
$mig \
--format='table[no-heading](NAME)'
}
function recreate-all-instances() {
project="$1"
mig="$2"
region=$(get-region-of-mig $project $mig)
instances=$(get-all-instances $project $mig | xargs echo -n | sed 's/\ /,/g')
gcloud --project="$project" \
compute instance-groups managed recreate-instances \
--region="$region" \
--instances="$instances" \
$mig
}