Include boot MAC address when listing nodes 61/4461/3
authorTodd Malsbary <todd.malsbary@intel.com>
Thu, 30 Sep 2021 18:47:03 +0000 (11:47 -0700)
committerTodd Malsbary <todd.malsbary@intel.com>
Mon, 4 Oct 2021 23:51:16 +0000 (16:51 -0700)
This enables the metal3 scripts to be used with both bare metal and
virtual machines.

Signed-off-by: Todd Malsbary <todd.malsbary@intel.com>
Change-Id: Ice18fe91bc7788b410604a20aff816d038fbb02b

deploy/metal3/scripts/01_metal3.sh
deploy/metal3/scripts/02_verify.sh
deploy/metal3/scripts/03_verify_deprovisioning.sh
env/lib/common.sh

index 77597db..d11d5b0 100755 (executable)
@@ -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
index a6a1023..cc2a87d 100755 (executable)
@@ -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
index 5c49d1d..7ffcc01 100755 (executable)
@@ -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')
index 9ac1431..78f4c12 100755 (executable)
@@ -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 {