-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset-primary-ips.sh
executable file
·43 lines (35 loc) · 1.1 KB
/
set-primary-ips.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
#!/usr/bin/env zsh
CLUSTER_TYPE="$1"
ROLES=(blade server storage management-server gpu-node)
if [[ -z "$CLUSTER_TYPE" ]]
then
echo_error "Please provide a cluster type"
exit 2
fi
for CLUSTER in "${(@f)$(nbx cluster type="$CLUSTER_TYPE" -j | jq -er '.[].name')}"
do
echo_info "Processing cluster: $CLUSTER"
for ROLE in "${ROLES[@]}"
do
echo_info "Cluster: $CLUSTER - Role: $ROLE"
DATA=$(nbx d cluster_id=$CLUSTER role=$ROLE -g \
--cols +interfaces.ip_addresses.address,interfaces.ip_addresses.id,interfaces.name \
--ids -j |
jq -er '[
.[] |
(.interfaces[] | select(.name == "fabric").ip_addresses[]) as $fabric_ip |
(.interfaces[] | select(.name == "IPMI").ip_addresses[]) as $oob_ip |
{
id: (.id | tonumber),
primary_ip4: ($fabric_ip.id | tonumber),
oob_ip: ($oob_ip.id | tonumber),
}
]')
if [[ "$DATA" == "[]" ]]
then
echo_warning "No data for $CLUSTER $ROLE"
continue
fi
nbx --noconfirm raw dcim/devices/ -X PATCH --data "$(jq -c <<< "$DATA")"
done
done