+ # The boot MAC address must be specified when a port is included
+ # in the IPMI driver address (i.e when using the VirtualBMC
+ # controller). Note that the below is a bit of a hack as it only
+ # checks the first entry in NODES_FILE for the port.
+ if cat "$NODES_FILE" |
+ jq -r '.nodes[0].ipmi_driver_info.address' | grep -c ':[0-9]\+$' >/dev/null; then
+ BOOT_LINK=$(cat "$NODES_FILE" |
+ jq -r '.nodes[0].net.links | map(.id=="provisioning_nic") | index(true)')
+ cat "$NODES_FILE" |
+ jq -r --argjson BOOT_LINK $BOOT_LINK '.nodes[] | [
+ .name,
+ .ipmi_driver_info.username,
+ .ipmi_driver_info.password,
+ .ipmi_driver_info.address,
+ .net.links[$BOOT_LINK].ethernet_mac_address,
+ .os.username,
+ .os.password,
+ .os.image_name
+ ] | @csv' |
+ sed 's/"//g'
+ else
+ cat "$NODES_FILE" |
+ jq -r '.nodes[] | [
+ .name,
+ .ipmi_driver_info.username,
+ .ipmi_driver_info.password,
+ .ipmi_driver_info.address,
+ "",
+ .os.username,
+ .os.password,
+ .os.image_name
+ ] | @csv' |
+ sed 's/"//g'
+ fi
+}
+
+# Returns "null" when the field is not present
+function networkdata_networks_field {
+ name=$1
+ network=$2
+ field=$3
+ NODES_FILE="${IRONIC_DATA_DIR}/nodes.json"
+ 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}
+}
+
+# Returns "null" when the field is not present
+function networkdata_links_field {
+ name=$1
+ link=$2
+ field=$3
+ NODES_FILE="${IRONIC_DATA_DIR}/nodes.json"
+ 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}
+}
+
+function node_networkdata {
+ name=$1
+
+ NODES_FILE="${IRONIC_DATA_DIR}/nodes.json"
+
+ if [ ! -f "$NODES_FILE" ]; then
+ exit 1
+ fi
+
+ printf " networks:\n"
+ for network in $(cat $NODES_FILE | jq -r --arg name "$name" '.nodes[] | select(.name==$name) | .net.networks[].id'); do
+ link=$(networkdata_networks_field $name $network "link")
+ type=$(networkdata_networks_field $name $network "type")
+ mac=$(networkdata_links_field $name $link "ethernet_mac_address")
+
+ # Optional values
+ ip_address=$(networkdata_networks_field $name $network "ip_address")
+ gateway=$(networkdata_networks_field $name $network "gateway")
+ dns_nameservers=$(networkdata_networks_field $name $network "dns_nameservers")
+
+ printf " ${network}:\n"
+ printf " macAddress: ${mac}\n"
+ printf " type: ${type}\n"
+ if [[ $ip_address != "null" ]]; then
+ printf " ipAddress: ${ip_address}\n"
+ fi
+ if [[ $gateway != "null" ]]; then
+ printf " gateway: ${gateway}\n"
+ fi
+ if [[ $dns_nameservers != "null" ]]; then
+ printf " nameservers: ${dns_nameservers}\n"
+ fi
+ done
+}
+
+function wait_for {
+ local -r interval=${WAIT_FOR_INTERVAL:-30s}
+ local -r max_tries=${WAIT_FOR_TRIES:-20}
+ local try=0
+ until "$@"; do
+ echo "[${try}/${max_tries}] - Waiting ${interval} for $*"
+ sleep ${interval}
+ try=$((try+1))
+ if [[ ${try} -ge ${max_tries} ]]; then
+ return 1
+ fi
+ done
+}
+
+function clone_baremetal_operator_repository {
+ mkdir -p $(dirname ${BMOPATH})
+ if [[ -d ${BMOPATH} && "${FORCE_REPO_UPDATE}" == "true" ]]; then
+ rm -rf "${BMOPATH}"
+ fi
+ if [ ! -d "${BMOPATH}" ] ; then
+ pushd $(dirname ${BMOPATH})
+ git clone "${BMOREPO}"
+ popd
+ else
+ pushd "${BMOPATH}"
+ git fetch
+ popd
+ fi
+ pushd "${BMOPATH}"
+ git reset --hard "${BMO_VERSION}"
+ popd
+}
+
+function install_kustomize {
+ curl -sL "https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2F${KUSTOMIZE_VERSION}/kustomize_${KUSTOMIZE_VERSION}_linux_amd64.tar.gz" -o kustomize_${KUSTOMIZE_VERSION}_linux_amd64.tar.gz
+ tar xzf kustomize_${KUSTOMIZE_VERSION}_linux_amd64.tar.gz --no-same-owner
+ sudo install -o root -g root -m 0755 kustomize /usr/local/bin/kustomize
+ rm kustomize_${KUSTOMIZE_VERSION}_linux_amd64.tar.gz kustomize
+ kustomize version
+}
+
+function install_clusterctl {
+ curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/${CAPI_VERSION}/clusterctl-linux-amd64 -o clusterctl
+ sudo install -o root -g root -m 0755 clusterctl /usr/local/bin/clusterctl
+ rm clusterctl
+ clusterctl version
+}
+
+function install_flux_cli {
+ export FLUX_VERSION
+ curl -s https://fluxcd.io/install.sh | sudo -E bash
+ flux --version