4 IRONIC_DATA_DIR=${IRONIC_DATA_DIR:-"/opt/ironic"}
5 NODES_FILE=${NODES_FILE:-"${IRONIC_DATA_DIR}/nodes.json"}
6 #IRONIC_PROVISIONING_INTERFACE is required to be provisioning, don't change it
7 IRONIC_INTERFACE=${IRONIC_INTERFACE:-}
8 IRONIC_PROVISIONING_INTERFACE=${IRONIC_PROVISIONING_INTERFACE:-"provisioning"}
9 IRONIC_PROVISIONING_INTERFACE_IP=${IRONIC_PROVISIONING_INTERFACE_IP:-"172.22.0.1"}
10 BM_IMAGE_URL=${BM_IMAGE_URL:-"https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img"}
11 BM_IMAGE=${BM_IMAGE:-"focal-server-cloudimg-amd64.img"}
13 #Baremetal operator repository URL
14 BMOREPO="${BMOREPO:-https://github.com/metal3-io/baremetal-operator.git}"
15 #Path to clone the baremetal operator repo
16 BMOPATH="/opt/src/github.com/metal3-io/baremetal-operator"
17 #Bare Metal Operator version to use
18 # If changing this, the value in deploy/ironic/icn/kustomization.yaml
19 # must also be changed
20 BMO_VERSION="capm3-v0.5.4"
23 KUDREPO="${KUDREPO:-https://github.com/onap/multicloud-k8s.git}"
24 #Path to clone the KuD repo
25 KUDPATH="/opt/src/github.com/onap/multicloud-k8s"
27 KUD_VERSION="8157bf63753839ce4e9006978816fad3f63ca2de"
30 EMCOREPO="${EMCOREPO:-https://gitlab.com/project-emco/core/emco-base.git}"
31 #Path to clone the EMCO repo
32 EMCOPATH="/opt/src/emco-base"
36 #Discard existing repo directory
37 FORCE_REPO_UPDATE="${FORCE_REPO_UPDATE:-false}"
39 # The kustomize version to use
40 KUSTOMIZE_VERSION="v4.5.2"
42 #Cluster API version to use
45 #Cluster API version to use
46 CAPM3_VERSION="v0.5.4"
48 #The flux version to use
51 #The sops version to use
54 #Cert-Manager version to use
55 CERT_MANAGER_VERSION="v1.7.1"
57 #CNI versions to use in cluster chart
58 CALICO_VERSION="v3.22.0"
59 FLANNEL_VERSION="v0.16.3"
63 KATA_WEBHOOK_VERSION="2.3.2"
65 #The kubectl version to install when KuD is not used to deploy the
66 #jump server K8s cluster
67 KUBECTL_VERSION="v1.20.7"
69 #The yq version to use
74 CPU_MANAGER_VERSION="v1.4.1"
75 KUBEVIRT_VERSION="v0.50.0"
77 NODUS_VERSION="dd9985e5be010b764b324b57c1afe985a59abf68"
82 #Runs curl with passed flags and provides
83 #additional error handling and debug information
85 #Function outputs server response body
86 #and performs validation of http_code
89 local curl_response_file="$(mktemp -p /tmp)"
90 local curl_common_flags=(-s -w "%{http_code}" -o "${curl_response_file}")
91 local command=(curl "${curl_common_flags[@]}" "$@")
93 echo "[INFO] Running '${command[@]}'" >&2
94 if ! status="$("${command[@]}")"; then
95 echo "[ERROR] Internal curl error! '$status'" >&2
96 cat "${curl_response_file}"
97 rm "${curl_response_file}"
100 echo "[INFO] Server replied with status: ${status}" >&2
101 cat "${curl_response_file}"
102 rm "${curl_response_file}"
103 if [[ "${status:0:1}" =~ [45] ]]; then
111 function list_nodes {
112 if [ ! -f "$NODES_FILE" ]; then
116 # The boot MAC address must be specified when a port is included
117 # in the IPMI driver address (i.e when using the VirtualBMC
118 # controller). Note that the below is a bit of a hack as it only
119 # checks the first entry in NODES_FILE for the port.
120 if cat "$NODES_FILE" |
121 jq -r '.nodes[0].ipmi_driver_info.address' | grep -c ':[0-9]\+$' >/dev/null; then
122 BOOT_LINK=$(cat "$NODES_FILE" |
123 jq -r '.nodes[0].net.links | map(.id=="provisioning_nic") | index(true)')
125 jq -r --argjson BOOT_LINK $BOOT_LINK '.nodes[] | [
127 .ipmi_driver_info.username,
128 .ipmi_driver_info.password,
129 .ipmi_driver_info.address,
130 .net.links[$BOOT_LINK].ethernet_mac_address,
140 .ipmi_driver_info.username,
141 .ipmi_driver_info.password,
142 .ipmi_driver_info.address,
152 function node_userdata {
156 COMPUTE_NODE_FQDN="$name.akraino.icn.org"
158 # validate that the user isn't expecting the deprecated
159 # COMPUTE_NODE_PASSWORD to be used
160 if [ "$password" != "${COMPUTE_NODE_PASSWORD:-$password}" ]; then
162 COMPUTE_NODE_PASSWORD "$COMPUTE_NODE_PASSWORD" not equal to nodes.json $name password "$password".
163 Unset COMPUTE_NODE_PASSWORD and retry.
169 if [ -n "$username" ]; then
170 printf " name: ${username}\n"
172 if [ -n "$password" ]; then
173 passwd=$(mkpasswd --method=SHA-512 --rounds 4096 "$password")
174 printf " hashedPassword: ${passwd}\n"
177 if [ -n "$COMPUTE_NODE_FQDN" ]; then
178 printf " fqdn: ${COMPUTE_NODE_FQDN}\n"
181 if [ ! -f $HOME/.ssh/id_rsa.pub ]; then
182 yes y | ssh-keygen -t rsa -N "" -f $HOME/.ssh/id_rsa
185 printf " sshAuthorizedKey: $(cat $HOME/.ssh/id_rsa.pub)\n"
188 # Returns "null" when the field is not present
189 function networkdata_networks_field {
193 cat $NODES_FILE | jq -c -r --arg name "$name" --arg network "$network" --arg field "$field" '.nodes[] | select(.name==$name) | .net.networks[] | select(.id==$network).'${field}
196 # Returns "null" when the field is not present
197 function networkdata_links_field {
201 cat $NODES_FILE | jq -c -r --arg name "$name" --arg link "$link" --arg field "$field" '.nodes[] | select(.name==$name) | .net.links[] | select(.id==$link).'${field}
204 function node_networkdata {
207 if [ ! -f "$NODES_FILE" ]; then
212 for network in $(cat $NODES_FILE | jq -r --arg name "$name" '.nodes[] | select(.name==$name) | .net.networks[].id'); do
213 link=$(networkdata_networks_field $name $network "link")
214 type=$(networkdata_networks_field $name $network "type")
215 mac=$(networkdata_links_field $name $link "ethernet_mac_address")
218 ip_address=$(networkdata_networks_field $name $network "ip_address")
219 gateway=$(networkdata_networks_field $name $network "gateway")
220 dns_nameservers=$(networkdata_networks_field $name $network "dns_nameservers")
222 printf " ${network}:\n"
223 printf " macAddress: ${mac}\n"
224 printf " type: ${type}\n"
225 if [[ $ip_address != "null" ]]; then
226 printf " ipAddress: ${ip_address}\n"
228 if [[ $gateway != "null" ]]; then
229 printf " gateway: ${gateway}\n"
231 if [[ $dns_nameservers != "null" ]]; then
232 printf " nameservers: ${dns_nameservers}\n"
238 local -r interval=${WAIT_FOR_INTERVAL:-30s}
239 local -r max_tries=${WAIT_FOR_TRIES:-20}
242 echo "[${try}/${max_tries}] - Waiting ${interval} for $*"
245 if [[ ${try} -ge ${max_tries} ]]; then
251 # This is intended to be used together with list_nodes in the
253 # list_nodes | while IFS=',' read -r name ipmi_username ipmi_password ipmi_address boot_mac os_username os_password os_image_name; do ...
254 function node_machine_values {
255 printf "machineName: ${name}\n"
256 printf "machineLabels:\n"
257 printf " machine: ${name}\n"
258 printf "bmcUsername: ${ipmi_username}\n"
259 printf "bmcPassword: ${ipmi_password}\n"
260 printf "bmcAddress: ipmi://${ipmi_address}\n"
261 if [[ ! -z ${boot_mac} ]]; then
262 printf "bootMACAddress: ${boot_mac}\n"
264 printf "imageName: ${BM_IMAGE}\n"
265 node_userdata ${name} ${os_username} ${os_password}
266 node_networkdata ${name}
269 function clone_repository {
273 mkdir -p $(dirname ${path})
274 if [[ -d ${path} && "${FORCE_REPO_UPDATE}" == "true" ]]; then
277 if [ ! -d "${path}" ] ; then
278 pushd $(dirname ${path})
287 git reset --hard "${version}"
291 function clone_baremetal_operator_repository {
292 clone_repository ${BMOPATH} ${BMOREPO} ${BMO_VERSION}
295 function clone_kud_repository {
296 clone_repository ${KUDPATH} ${KUDREPO} ${KUD_VERSION}
299 function clone_emco_repository {
300 clone_repository ${EMCOPATH} ${EMCOREPO} ${EMCO_VERSION}
303 function fetch_image {
304 if [[ "${BM_IMAGE_URL}" && "${BM_IMAGE}" ]]; then
305 mkdir -p "${IRONIC_DATA_DIR}/html/images"
306 pushd ${IRONIC_DATA_DIR}/html/images
308 if [[ -f "${BM_IMAGE}" ]]; then
309 local_checksum=$(md5sum ${BM_IMAGE} | awk '{print $1}')
311 remote_checksum=$(curl -sL "$(dirname ${BM_IMAGE_URL})/MD5SUMS" | grep ${BM_IMAGE} | awk '{print $1}')
312 if [[ ${local_checksum} != ${remote_checksum} ]]; then
313 curl -o ${BM_IMAGE} --insecure --compressed -O -L ${BM_IMAGE_URL}
314 md5sum ${BM_IMAGE} | awk '{print $1}' > ${BM_IMAGE}.md5sum