Include boot MAC address when listing nodes
[icn.git] / deploy / metal3 / scripts / 01_metal3.sh
index 2ad233c..d11d5b0 100755 (executable)
@@ -12,6 +12,11 @@ if [[ $EUID -ne 0 ]]; then
     exit 1
 fi
 
+#Path to clone the metal3 dev env repo
+M3PATH="$(go env GOPATH)/src/github.com/metal3-io"
+#Path to clone the baremetal operator repo
+BMOPATH="${M3PATH}/baremetal-operator"
+
 IMAGE_URL=http://172.22.0.1/images/${BM_IMAGE}
 IMAGE_CHECKSUM=http://172.22.0.1/images/${BM_IMAGE}.md5sum
 
@@ -31,32 +36,6 @@ function clone_repos {
     popd
 }
 
-function get_default_interface_ipaddress {
-    local _ip=$1
-    local _default_interface=$(awk '$2 == 00000000 { print $1 }' /proc/net/route)
-    local _ipv4address=$(ip addr show dev $_default_interface | awk '$1 == "inet" { sub("/.*", "", $2); print $2 }')
-    eval $_ip="'$_ipv4address'"
-}
-
-function create_ssh_key {
-    #ssh key for compute node to communicate back to bootstrap server
-    mkdir -p $BUILD_DIR/ssh_key
-    ssh-keygen -C "compute.icn.akraino.lfedge.org" -f $BUILD_DIR/ssh_key/id_rsa
-    cat $BUILD_DIR/ssh_key/id_rsa.pub >> $HOME/.ssh/authorized_keys
-}
-
-function set_compute_key {
-    _SSH_LOCAL_KEY=$(cat $BUILD_DIR/ssh_key/id_rsa)
-    cat << EOF
-write_files:
-- path: /opt/ssh_id_rsa
-    owner: root:root
-    permissions: '0600'
-    content: |
-    $_SSH_LOCAL_KEY
-EOF
-}
-
 function deprovision_compute_node {
     name="$1"
     if kubectl get baremetalhost $name -n metal3 &>/dev/null; then
@@ -65,25 +44,6 @@ function deprovision_compute_node {
     fi
 }
 
-function set_compute_ssh_config {
-    get_default_interface_ipaddress default_addr
-    cat << EOF
-- path: /root/.ssh/config
-    owner: root:root
-    permissions: '0600'
-    content: |
-    Host bootstrapmachine $default_addr
-    HostName $default_addr
-    IdentityFile /opt/ssh_id_rsa
-    User $USER
-- path: /etc/apt/sources.list
-    owner: root:root
-    permissions: '0665'
-    content: |
-    deb [trusted=yes] ssh://$USER@$default_addr:$LOCAL_APT_REPO ./
-EOF
-}
-
 # documentation for the values below may be found at
 # https://cloudinit.readthedocs.io/en/latest/topics/modules.html
 function create_userdata {
@@ -159,10 +119,26 @@ function remove_baremetal_operator {
 }
 
 function cloud_init_scripts {
-    # The "intel_iommu=on iommu=pt" kernel command line is necessary
-    # for QAT support.
+    # set_dhcp_indentifier.sh:
+    #   The IP address assigned to the provisioning NIC will change
+    #   due to IPA using the MAC address as the client ID and systemd
+    #   using a different ID.  Tell systemd to use the MAC as the
+    #   client ID.  We can't do this in the network data as only the
+    #   JSON format is supported by metal3, and the JSON format does
+    #   not support the dhcp-identifier field.
+    # set_kernel_cmdline.sh:
+    #   The "intel_iommu=on iommu=pt" kernel command line is necessary
+    #   for QAT support.
     cat << 'EOF'
 write_files:
+- path: /var/lib/cloud/scripts/per-instance/set_dhcp_identifier.sh
+  owner: root:root
+  permissions: '0777'
+  content: |
+    #!/usr/bin/env bash
+    set -eux -o pipefail
+    sed -i -e '/dhcp4: true$/!b' -e 'h;s/\S.*/dhcp-identifier: mac/;H;g' /etc/netplan/50-cloud-init.yaml
+    netplan apply
 - path: /var/lib/cloud/scripts/per-instance/set_kernel_cmdline.sh
   owner: root:root
   permissions: '0777'
@@ -208,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
@@ -218,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
@@ -247,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
@@ -322,10 +299,3 @@ echo "deprovision - deprovision baremetal node as specified in common.sh"
 echo "clean       - clean all the bmh resources"
 echo "remove      - remove baremetal operator"
 exit 1
-
-#Following code is tested for the offline mode
-#Will be intergrated for the offline mode for ICNi v.0.1.0 beta
-#create_ssh_key
-#create_userdata
-#set_compute_key
-#set_compute_ssh_config