4 IRONIC_DATA_DIR=${IRONIC_DATA_DIR:-"/opt/ironic"}
5 #IRONIC_PROVISIONING_INTERFACE is required to be provisioning, don't change it
6 IRONIC_INTERFACE=${IRONIC_INTERFACE:-}
7 IRONIC_PROVISIONING_INTERFACE=${IRONIC_PROVISIONING_INTERFACE:-"provisioning"}
8 IRONIC_IPMI_INTERFACE=${IRONIC_IPMI_INTERFACE:-}
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 BMO_VERSION="capm3-v0.5.1"
21 KUDREPO="${KUDREPO:-https://github.com/onap/multicloud-k8s.git}"
22 #Path to clone the KuD repo
23 KUDPATH="/opt/src/github.com/onap/multicloud-k8s"
25 KUD_VERSION="ed96bca7fe415f1636d82c26af15d7474bdfe876"
28 EMCOREPO="${EMCOREPO:-https://github.com/open-ness/EMCO.git}"
29 #Path to clone the EMCO repo
30 EMCOPATH="/opt/src/github.com/open-ness/EMCO"
32 EMCO_VERSION="openness-21.03.06"
34 #Discard existing repo directory
35 FORCE_REPO_UPDATE="${FORCE_REPO_UPDATE:-true}"
37 # The kustomize version to use
38 KUSTOMIZE_VERSION="v4.3.0"
40 #Cluster API version to use
43 #Cluster API version to use
44 CAPM3_VERSION="v0.5.1"
46 #The flux version to use
49 #The sops version to use
54 #Runs curl with passed flags and provides
55 #additional error handling and debug information
57 #Function outputs server response body
58 #and performs validation of http_code
61 local curl_response_file="$(mktemp -p /tmp)"
62 local curl_common_flags=(-s -w "%{http_code}" -o "${curl_response_file}")
63 local command=(curl "${curl_common_flags[@]}" "$@")
65 echo "[INFO] Running '${command[@]}'" >&2
66 if ! status="$("${command[@]}")"; then
67 echo "[ERROR] Internal curl error! '$status'" >&2
68 cat "${curl_response_file}"
69 rm "${curl_response_file}"
72 echo "[INFO] Server replied with status: ${status}" >&2
73 cat "${curl_response_file}"
74 rm "${curl_response_file}"
75 if [[ "${status:0:1}" =~ [45] ]]; then
84 NODES_FILE="${IRONIC_DATA_DIR}/nodes.json"
86 if [ ! -f "$NODES_FILE" ]; then
90 # The boot MAC address must be specified when a port is included
91 # in the IPMI driver address (i.e when using the VirtualBMC
92 # controller). Note that the below is a bit of a hack as it only
93 # checks the first entry in NODES_FILE for the port.
94 if cat "$NODES_FILE" |
95 jq -r '.nodes[0].ipmi_driver_info.address' | grep -c ':[0-9]\+$' >/dev/null; then
96 BOOT_LINK=$(cat "$NODES_FILE" |
97 jq -r '.nodes[0].net.links | map(.id=="provisioning_nic") | index(true)')
99 jq -r --argjson BOOT_LINK $BOOT_LINK '.nodes[] | [
101 .ipmi_driver_info.username,
102 .ipmi_driver_info.password,
103 .ipmi_driver_info.address,
104 .net.links[$BOOT_LINK].ethernet_mac_address,
114 .ipmi_driver_info.username,
115 .ipmi_driver_info.password,
116 .ipmi_driver_info.address,
126 # Returns "null" when the field is not present
127 function networkdata_networks_field {
131 NODES_FILE="${IRONIC_DATA_DIR}/nodes.json"
132 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}
135 # Returns "null" when the field is not present
136 function networkdata_links_field {
140 NODES_FILE="${IRONIC_DATA_DIR}/nodes.json"
141 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}
144 function node_networkdata {
147 NODES_FILE="${IRONIC_DATA_DIR}/nodes.json"
149 if [ ! -f "$NODES_FILE" ]; then
154 for network in $(cat $NODES_FILE | jq -r --arg name "$name" '.nodes[] | select(.name==$name) | .net.networks[].id'); do
155 link=$(networkdata_networks_field $name $network "link")
156 type=$(networkdata_networks_field $name $network "type")
157 mac=$(networkdata_links_field $name $link "ethernet_mac_address")
160 ip_address=$(networkdata_networks_field $name $network "ip_address")
161 gateway=$(networkdata_networks_field $name $network "gateway")
162 dns_nameservers=$(networkdata_networks_field $name $network "dns_nameservers")
164 printf " ${network}:\n"
165 printf " macAddress: ${mac}\n"
166 printf " type: ${type}\n"
167 if [[ $ip_address != "null" ]]; then
168 printf " ipAddress: ${ip_address}\n"
170 if [[ $gateway != "null" ]]; then
171 printf " gateway: ${gateway}\n"
173 if [[ $dns_nameservers != "null" ]]; then
174 printf " nameservers: ${dns_nameservers}\n"
180 local -r interval=${WAIT_FOR_INTERVAL:-30s}
181 local -r max_tries=${WAIT_FOR_TRIES:-20}
184 echo "[${try}/${max_tries}] - Waiting ${interval} for $*"
187 if [[ ${try} -ge ${max_tries} ]]; then
193 function clone_repository {
197 mkdir -p $(dirname ${path})
198 if [[ -d ${path} && "${FORCE_REPO_UPDATE}" == "true" ]]; then
201 if [ ! -d "${path}" ] ; then
202 pushd $(dirname ${path})
211 git reset --hard "${version}"
215 function clone_baremetal_operator_repository {
216 clone_repository ${BMOPATH} ${BMOREPO} ${BMO_VERSION}
219 function clone_kud_repository {
220 clone_repository ${KUDPATH} ${KUDREPO} ${KUD_VERSION}
223 function clone_emco_repository {
224 clone_repository ${EMCOPATH} ${EMCOREPO} ${EMCO_VERSION}
227 function install_kustomize {
228 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
229 tar xzf kustomize_${KUSTOMIZE_VERSION}_linux_amd64.tar.gz --no-same-owner
230 sudo install -o root -g root -m 0755 kustomize /usr/local/bin/kustomize
231 rm kustomize_${KUSTOMIZE_VERSION}_linux_amd64.tar.gz kustomize
235 function install_clusterctl {
236 curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/${CAPI_VERSION}/clusterctl-linux-amd64 -o clusterctl
237 sudo install -o root -g root -m 0755 clusterctl /usr/local/bin/clusterctl
242 function install_flux_cli {
244 curl -s https://fluxcd.io/install.sh | sudo -E bash
248 function install_emcoctl {
249 clone_emco_repository
250 make -C ${EMCOPATH}/src/tools/emcoctl
251 sudo install -o root -g root -m 0755 ${EMCOPATH}/bin/emcoctl/emcoctl /usr/local/bin/emcoctl
254 function install_sops {
255 curl -L https://github.com/mozilla/sops/releases/download/${SOPS_VERSION}/sops-${SOPS_VERSION}.linux -o sops
256 sudo install -o root -g root -m 0755 sops /usr/local/bin/sops
261 function fetch_image {
262 if [[ "${BM_IMAGE_URL}" && "${BM_IMAGE}" ]]; then
263 mkdir -p "${IRONIC_DATA_DIR}/html/images"
264 pushd ${IRONIC_DATA_DIR}/html/images
266 if [[ -f "${BM_IMAGE}" ]]; then
267 local_checksum=$(md5sum ${BM_IMAGE} | awk '{print $1}')
269 remote_checksum=$(curl -sL "$(dirname ${BM_IMAGE_URL})/MD5SUMS" | grep ${BM_IMAGE} | awk '{print $1}')
270 if [[ ${local_checksum} != ${remote_checksum} ]]; then
271 curl -o ${BM_IMAGE} --insecure --compressed -O -L ${BM_IMAGE_URL}
272 md5sum ${BM_IMAGE} | awk '{print $1}' > ${BM_IMAGE}.md5sum