From 30b77af0fb5fc89e7b9e76f4e6e33aaf82832945 Mon Sep 17 00:00:00 2001 From: Todd Malsbary Date: Thu, 30 Sep 2021 11:47:03 -0700 Subject: [PATCH] Include boot MAC address when listing nodes This enables the metal3 scripts to be used with both bare metal and virtual machines. Signed-off-by: Todd Malsbary Change-Id: Ice18fe91bc7788b410604a20aff816d038fbb02b --- deploy/metal3/scripts/01_metal3.sh | 7 ++-- deploy/metal3/scripts/02_verify.sh | 2 +- deploy/metal3/scripts/03_verify_deprovisioning.sh | 2 +- env/lib/common.sh | 45 +++++++++++++++++------ 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/deploy/metal3/scripts/01_metal3.sh b/deploy/metal3/scripts/01_metal3.sh index 77597db..d11d5b0 100755 --- a/deploy/metal3/scripts/01_metal3.sh +++ b/deploy/metal3/scripts/01_metal3.sh @@ -184,7 +184,7 @@ EOF } function make_bm_hosts { - while IFS=',' read -r name ipmi_username ipmi_password ipmi_address os_username os_password os_image_name; do + while IFS=',' read -r name ipmi_username ipmi_password ipmi_address boot_mac os_username os_password os_image_name; do create_userdata $name $os_username $os_password apply_userdata_credential $name create_networkdata $name @@ -194,6 +194,7 @@ function make_bm_hosts { -address "ipmi://$ipmi_address" \ -password "$ipmi_password" \ -user "$ipmi_username" \ + -boot-mac "$boot_mac" \ "$name" > $name-bm-node.yaml printf " image:" >> $name-bm-node.yaml @@ -223,13 +224,13 @@ function configure_nodes { } function remove_bm_hosts { - while IFS=',' read -r name ipmi_username ipmi_password ipmi_address os_username os_password os_image_name; do + while IFS=',' read -r name ipmi_username ipmi_password ipmi_address boot_mac os_username os_password os_image_name; do deprovision_compute_node $name done } function cleanup { - while IFS=',' read -r name ipmi_username ipmi_password ipmi_address os_username os_password os_image_name; do + while IFS=',' read -r name ipmi_username ipmi_password ipmi_address boot_mac os_username os_password os_image_name; do kubectl delete --ignore-not-found=true bmh $name -n metal3 kubectl delete --ignore-not-found=true secrets $name-bmc-secret -n metal3 kubectl delete --ignore-not-found=true secrets $name-user-data -n metal3 diff --git a/deploy/metal3/scripts/02_verify.sh b/deploy/metal3/scripts/02_verify.sh index a6a1023..cc2a87d 100755 --- a/deploy/metal3/scripts/02_verify.sh +++ b/deploy/metal3/scripts/02_verify.sh @@ -14,7 +14,7 @@ function check_provisioned { declare -i prev_host_state=0 declare -i j=0 echo "Baremetal state: 1 means provisioned & 0 means not yet provisioned" - while IFS=',' read -r name ipmi_username ipmi_password ipmi_address os_username os_password os_image_name; do + while IFS=',' read -r name ipmi_username ipmi_password ipmi_address boot_mac os_username os_password os_image_name; do declare -i current_host_state=0 state=$(kubectl get baremetalhosts $name -n metal3 -o json | jq -r '.status.provisioning.state') echo "Baremetal host metal3 state - "$name" : "$state diff --git a/deploy/metal3/scripts/03_verify_deprovisioning.sh b/deploy/metal3/scripts/03_verify_deprovisioning.sh index 5c49d1d..7ffcc01 100755 --- a/deploy/metal3/scripts/03_verify_deprovisioning.sh +++ b/deploy/metal3/scripts/03_verify_deprovisioning.sh @@ -14,7 +14,7 @@ function check_deprovisioned { declare -i prev_host_state=0 declare -i j=0 echo "Baremetal state: 1 means deprovisioned & 0 means not yet deprovisioned" - while IFS=',' read -r name ipmi_username ipmi_password ipmi_address os_username os_password os_image_name; do + while IFS=',' read -r name ipmi_username ipmi_password ipmi_address boot_mac os_username os_password os_image_name; do declare -i current_host_state=0 if kubectl get baremetalhost $name -n metal3 &>/dev/null; then state=$(kubectl get baremetalhosts $name -n metal3 -o json | jq -r '.status.provisioning.state') diff --git a/env/lib/common.sh b/env/lib/common.sh index 9ac1431..78f4c12 100755 --- a/env/lib/common.sh +++ b/env/lib/common.sh @@ -63,17 +63,40 @@ function list_nodes { exit 1 fi - 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' + # 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 } function node_networkdata { -- 2.16.6