-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnodelist-generator.sh
executable file
·122 lines (102 loc) · 2.6 KB
/
nodelist-generator.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
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
#!/bin/bash
#
PROG=$(basename "$0")
declare -A POOLS=()
USERNAME_BASE64=$(echo -n "admin" | base64)
PASSWORD_BASE64=$(echo -n "mypass" | base64)
function usage {
cat <<EOF
Usage: ${PROG} ...
Parameters:
--resourcepool <name:prefix:size>
Example:
${0} --resourcepool master:dummy-sp-64g:5 --resourcepool worker:dummy-dp-128g:3
EOF
exit 1
}
function header {
cat <<EOF
kind: ConfigMap
apiVersion: v1
metadata:
name: loopback-adaptor-nodelist
namespace: oran-hwmgr-plugin
data:
resources: |
EOF
}
function resourcepools {
echo " resourcepools:"
mapfile -t sorted_pools < <( IFS=$'\n'; sort -u <<<"${!POOLS[*]}" )
for pool in "${sorted_pools[@]}"; do
echo " - ${pool}"
done
}
function nodes {
echo " nodes:"
group=0
mapfile -t sorted_pools < <( IFS=$'\n'; sort -u <<<"${!POOLS[*]}" )
for pool in "${sorted_pools[@]}"; do
value="${POOLS[${pool}]}"
prefix=$(echo "${value}" | awk -F: '{print $1}')
size=$(echo "${value}" | awk -F: '{print $2}')
group=$((group+1))
for ((i=0;i<${size};i++)); do
nodename=${prefix}-${i}
ip="192.168.${group}.${i}"
mac=$(printf "c6:b6:13:a0:%02x:%02x" ${group} ${i})
cat <<EOF
${nodename}:
poolID: ${pool}
bmc:
address: "idrac-virtualmedia+https://${ip}/redfish/v1/Systems/System.Embedded.1"
username-base64: ${USERNAME_BASE64}
password-base64: ${PASSWORD_BASE64}
interfaces:
- name: eth0
label: bootable-interface
macAddress: "${mac}"
EOF
done
done
}
#
# Process cmdline arguments
#
longopts=(
"help"
"resourcepool:"
)
longopts_str=$(IFS=,; echo "${longopts[*]}")
if ! OPTS=$(getopt -o "hp:" --long "${longopts_str}" --name "$0" -- "$@"); then
usage
exit 1
fi
eval set -- "${OPTS}"
while :; do
case "$1" in
-p|--resourcepool)
value="$2"
name=$(echo "${value}" | awk -F: '{print $1}')
prefix=$(echo "${value}" | awk -F: '{print $2}')
size=$(echo "${value}" | awk -F: '{print $3}')
POOLS+=(["${name}"]="${prefix}:${size}")
shift 2
;;
--)
shift
break ;;
-h|--help)
usage
;;
*)
usage
;;
esac
done
if [ "${#POOLS[@]}" -eq 0 ]; then
usage
fi
header
resourcepools
nodes