-
Notifications
You must be signed in to change notification settings - Fork 1
/
generator.sh
executable file
·123 lines (103 loc) · 2.69 KB
/
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
122
#!/bin/bash
#
PROG=$(basename "$0")
declare -A PROFILES=()
USERNAME_BASE64=$(echo -n "admin" | base64)
PASSWORD_BASE64=$(echo -n "mypass" | base64)
function usage {
cat <<EOF
Usage: ${PROG} ...
Parameters:
--profile <name:prefix:size>
Example:
${0} --profile profile-spr-single-processor-64G:dummy-sp-64g:5 --profile profile-spr-dual-processor-128G:dummy-dp-128g:3
EOF
exit 1
}
function header {
cat <<EOF
kind: ConfigMap
apiVersion: v1
metadata:
name: nodelist
namespace: oran-hwmgr-plugin-test
data:
resources: |
EOF
}
function hwprofiles {
echo " hwprofiles:"
mapfile -t sorted_profiles < <( IFS=$'\n'; sort -u <<<"${!PROFILES[*]}" )
for profile in "${sorted_profiles[@]}"; do
echo " - ${profile}"
done
}
function nodes {
echo " nodes:"
group=0
mapfile -t sorted_profiles < <( IFS=$'\n'; sort -u <<<"${!PROFILES[*]}" )
for profile in "${sorted_profiles[@]}"; do
value="${PROFILES[${profile}]}"
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}:
hwprofile: ${profile}
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}"
hostname: "${nodename}.localhost"
EOF
done
done
}
#
# Process cmdline arguments
#
longopts=(
"help"
"profile:"
)
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|--profile)
value="$2"
name=$(echo "${value}" | awk -F: '{print $1}')
prefix=$(echo "${value}" | awk -F: '{print $2}')
size=$(echo "${value}" | awk -F: '{print $3}')
PROFILES+=(["${name}"]="${prefix}:${size}")
shift 2
;;
--)
shift
break ;;
-h|--help)
usage
;;
*)
usage
;;
esac
done
if [ "${#PROFILES[@]}" -eq 0 ]; then
usage
fi
header
hwprofiles
nodes