#!/bin/bash # # Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved. # # NVIDIA CORPORATION and its licensors retain all intellectual property # and proprietary rights in and to this software, related documentation # and any modifications thereto. Any use, reproduction, disclosure or # distribution of this software and related documentation without an express # license agreement from NVIDIA CORPORATION is strictly prohibited. # # This script helps configure Redfish Host Interface #set -e set -u set -o pipefail IF_DESIRED_NAME="bmc_redfish0" INTF_GREP_STR="CDC Notification Interface\|CDC Ethernet Control Model" # Use ipcalc to return netmask in CIDR notation # Arg1 is IPv4 Address and Arg2 is Netmask get_nmask_cidr() { ipcalc $1 $2 | awk '/Netmask: / {print $4}' } get_network_configuration_tool() { # If netplan is present and renderer is set to "networkd", then # we know netplan is being used if command -v netplan &> /dev/null; then for p in `find "/etc/netplan/" -maxdepth 1 -type f -name "*.yaml"`; do if grep -v -P "^ *#" $p | grep "renderer" | grep -q "networkd"; then echo "Netplan" return fi done fi # If NetworkManager is installed and active, then we know # NetworkManager is being used if command -v NetworkManager &> /dev/null; then if systemctl is-active --quiet NetworkManager; then echo "NetworkManager" return fi fi # Now we take our best guess. Both can be installed, but we # don't know yet how the renderer will be set. if command -v NetworkManager &> /dev/null; then echo "NetworkManager" elif command -v netplan &> /dev/null; then echo "Netplan" else echo "Unknown" fi return } echo "Detecting Network Configuration Tool" net_config_tool=$(get_network_configuration_tool) case $net_config_tool in "Netplan" | "NetworkManager") echo "System is using Network Configuration Tool:" $net_config_tool ;; *) echo "System is using an unsupported Network Configuration Tool" exit esac echo "Detecting Redfish Interface name..." for INTERFACE in /sys/class/net/*; do if [[ -d "${INTERFACE}" ]]; then if [[ -f "${INTERFACE}/device/interface" ]]; then if grep -q "${INTF_GREP_STR}" ${INTERFACE}/device/interface; then INTERFACE_NAME=$(basename ${INTERFACE}) echo "Redfish Interface ${INTERFACE_NAME} found" MAC_ADDRESS=$(cat "/sys/class/net/${INTERFACE_NAME}/address") echo "Identifying Management Controller Host Interface IPv4 Address" IPADDR=$(dmidecode -t 42 | awk '/IPv4 Address: / {print $3}' | tail -n1) NMASK=$(dmidecode -t 42 | awk '/IPv4 Mask: / {print $3}' | tail -n1) if [[ "${NMASK}" =~ ^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$ ]]; then NMASK_CIDR=$(get_nmask_cidr "${IPADDR}" "${NMASK}") else echo "Netmask incorrect" fi if [[ "${IPADDR}" =~ ^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$ ]]; then if [[ $net_config_tool == "Netplan" ]]; then # Create a netplan config at /etc/netplan cat <