From 13c6b6bdf1fd2bdb1d1b7c7b069f7ae7e0559310 Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Thu, 17 Jul 2014 13:36:24 +0100 Subject: [PATCH] Add element for hardware discovery ramdisk for ironic-discoverd ironic-discoverd [1] is a StackForge project for conducting hardware properties discovery via booting a special discovery ramdisk and interrogating hardware from within it. It aims to be one of the official means of hardware properties discovery for Ironic in Kilo release [2]. The ramdisk collects hardware information from the machine it's booted on and posts it to the URL provided via kernel argument 'discoverd_callback_url'. [1] https://pypi.python.org/pypi/ironic-discoverd [2] https://review.openstack.org/#/c/135605/ Co-Authored-By: Lucas Alvares Gomes Change-Id: Ic81fe8b3bd0884971bb522b48658c7ee538a31f2 --- elements/ironic-discoverd-ramdisk/README.md | 19 ++++++ .../binary-deps.d/discovery-ironic | 6 ++ .../init.d/80-discovery-ironic | 60 +++++++++++++++++++ .../51-discovery-ironic-install-util-linux | 6 ++ .../53-discovery-ironic-install-curl | 6 ++ .../54-discovery-ironic-install-dmidecode | 6 ++ .../55-discovery-ironic-install-ipmitool | 6 ++ 7 files changed, 109 insertions(+) create mode 100644 elements/ironic-discoverd-ramdisk/README.md create mode 100644 elements/ironic-discoverd-ramdisk/binary-deps.d/discovery-ironic create mode 100644 elements/ironic-discoverd-ramdisk/init.d/80-discovery-ironic create mode 100755 elements/ironic-discoverd-ramdisk/install.d/51-discovery-ironic-install-util-linux create mode 100755 elements/ironic-discoverd-ramdisk/install.d/53-discovery-ironic-install-curl create mode 100755 elements/ironic-discoverd-ramdisk/install.d/54-discovery-ironic-install-dmidecode create mode 100755 elements/ironic-discoverd-ramdisk/install.d/55-discovery-ironic-install-ipmitool diff --git a/elements/ironic-discoverd-ramdisk/README.md b/elements/ironic-discoverd-ramdisk/README.md new file mode 100644 index 00000000..120bc74d --- /dev/null +++ b/elements/ironic-discoverd-ramdisk/README.md @@ -0,0 +1,19 @@ +ironic-discoverd [1] is a StackForge project for conducting hardware properties +discovery via booting a special discovery ramdisk and interrogating hardware +from within it. + +This ramdisk collects hardware information from the machine +it's booted on and posts it to the URL provided via +kernel argument 'discoverd_callback_url'. + +The hardware information collected by the ramdisk are: + +* BMC IP address (may be required for associating with existing node in Ironic) +* CPU count and architecture +* Memory amount in MiB +* Hard drive size in GiB +* IP and mac addresses for all NICs except the loopback + +The machine is halted at the end of the process. + +[1] https://pypi.python.org/pypi/ironic-discoverd diff --git a/elements/ironic-discoverd-ramdisk/binary-deps.d/discovery-ironic b/elements/ironic-discoverd-ramdisk/binary-deps.d/discovery-ironic new file mode 100644 index 00000000..dad55fd1 --- /dev/null +++ b/elements/ironic-discoverd-ramdisk/binary-deps.d/discovery-ironic @@ -0,0 +1,6 @@ +curl +dmidecode +fdisk +ipmitool +lscpu +wc diff --git a/elements/ironic-discoverd-ramdisk/init.d/80-discovery-ironic b/elements/ironic-discoverd-ramdisk/init.d/80-discovery-ironic new file mode 100644 index 00000000..5e70d335 --- /dev/null +++ b/elements/ironic-discoverd-ramdisk/init.d/80-discovery-ironic @@ -0,0 +1,60 @@ +readonly DISCOVERD_URL=$(get_kernel_parameter discoverd_callback_url) + +function request_curl(){ + HTTP_METHOD=$1 + URL=$2 + DATA=$3 + + if [ ! -z "$DATA" ]; then + DATA="\"-d \"$DATA\"\"" + fi + + RESULT=$(eval curl -i -X "$HTTP_METHOD" \ + "-H 'Accept: application/json'" \ + "-H 'Content-Type: application/json'" \ + "$DATA" \ + "$URL") || troubleshoot + # CURL can't return error code on 4xx error + if echo $RESULT | grep "HTTP/1.0 4"; then + echo "Ironic API returned error: $RESULT" + troubleshoot + fi + echo $RESULT +} + +IFACES= +for iface in $(ls /sys/class/net/ | grep -v lo) +do + MAC=$(ip link show $iface | awk '/ether/ {print $2}') + IP=$(ip addr show $iface | awk '/inet / { sub(/\/.*/, "", $2); print $2 }') + if [ ! -z "$MAC" ]; then + IFACES="$IFACES,\"$iface\":{\"mac\":\"$MAC\",\"ip\":\"$IP\"}" + fi +done +IFACES="{$(echo $IFACES | sed s/,//)}" + +# NOTE(dtantsur): workaround for IPMI device not present on some systems +modprobe ipmi_msghandler || echo "WARNING: modprobe failed, ipmitool call may fail" +modprobe ipmi_devintf || echo "WARNING: modprobe failed, ipmitool call may fail" +modprobe ipmi_si || echo "WARNING: modprobe failed, ipmitool call may fail" + +BMC_ADDRESS=$(ipmitool lan print | grep -e "IP Address [^S]" | awk '{ print $4 }') + +CPU_ARCH=$(lscpu | grep Architecture | awk '{ print $2 }') +# NOTE(lucasagomes): dmidecode because we want to know the total +# memory in the system, even the reserved part to the BIOS +RAM=$(dmidecode -t 16 | grep 'Maximum Capacity' | awk '{if ($4 == "GB") s+=$3*1024; else s+=$3;} END {print s}') +CPUS=$(cat /proc/cpuinfo | grep processor | wc -l) +disk_bytes=$(fdisk -l | grep Disk | awk '{print $5}' | head -n 1) +# NOTE(dtantsur): -1 is required to give Ironic some spacing for partitioning and may be removed later +DISK_SIZE=$(($disk_bytes/1024/1024/1024 - 1)) + +NODE_DATA="'{\"ipmi_address\":\"$BMC_ADDRESS\",\"local_gb\":$DISK_SIZE,\"memory_mb\":$RAM,\"cpus\":$CPUS,\"cpu_arch\":\"$CPU_ARCH\"" +NODE_DATA="$NODE_DATA,\"interfaces\":$IFACES}'" +echo Collected $NODE_DATA +NODE_RESP=$(request_curl POST $DISCOVERD_URL $NODE_DATA) + +echo "Node is now discovered! Halting..." +# Give user a chance of seeing the output +sleep 5 +poweroff -f diff --git a/elements/ironic-discoverd-ramdisk/install.d/51-discovery-ironic-install-util-linux b/elements/ironic-discoverd-ramdisk/install.d/51-discovery-ironic-install-util-linux new file mode 100755 index 00000000..236ecd7f --- /dev/null +++ b/elements/ironic-discoverd-ramdisk/install.d/51-discovery-ironic-install-util-linux @@ -0,0 +1,6 @@ +#!/bin/bash + +set -eu +set -o pipefail + +install-packages util-linux diff --git a/elements/ironic-discoverd-ramdisk/install.d/53-discovery-ironic-install-curl b/elements/ironic-discoverd-ramdisk/install.d/53-discovery-ironic-install-curl new file mode 100755 index 00000000..0871746e --- /dev/null +++ b/elements/ironic-discoverd-ramdisk/install.d/53-discovery-ironic-install-curl @@ -0,0 +1,6 @@ +#!/bin/bash + +set -eu +set -o pipefail + +install-packages curl diff --git a/elements/ironic-discoverd-ramdisk/install.d/54-discovery-ironic-install-dmidecode b/elements/ironic-discoverd-ramdisk/install.d/54-discovery-ironic-install-dmidecode new file mode 100755 index 00000000..d9a309e4 --- /dev/null +++ b/elements/ironic-discoverd-ramdisk/install.d/54-discovery-ironic-install-dmidecode @@ -0,0 +1,6 @@ +#!/bin/bash + +set -eu +set -o pipefail + +install-packages dmidecode diff --git a/elements/ironic-discoverd-ramdisk/install.d/55-discovery-ironic-install-ipmitool b/elements/ironic-discoverd-ramdisk/install.d/55-discovery-ironic-install-ipmitool new file mode 100755 index 00000000..90abd012 --- /dev/null +++ b/elements/ironic-discoverd-ramdisk/install.d/55-discovery-ironic-install-ipmitool @@ -0,0 +1,6 @@ +#!/bin/bash + +set -eu +set -o pipefail + +install-packages ipmitool