2015-01-27 09:52:08 +00:00
|
|
|
DISCOVERD_URL=$(get_kernel_parameter discoverd_callback_url)
|
2015-02-09 13:51:11 +00:00
|
|
|
|
2015-01-27 09:52:08 +00:00
|
|
|
if [ -z "$DISCOVERD_URL" ]; then
|
|
|
|
# Some old ramdisks are around
|
|
|
|
DISCOVERD_URL=$(get_kernel_parameter ironic_callback_url)
|
|
|
|
if [ -z "$DISCOVERD_URL" ]; then
|
|
|
|
echo "No discoverd_callback_url supplied"
|
|
|
|
troubleshoot
|
|
|
|
else
|
|
|
|
echo "WARNING: deprecated option ironic_callback_url"
|
|
|
|
echo "WARNING: use discoverd_callback_url instead"
|
|
|
|
fi
|
|
|
|
fi
|
2014-07-17 12:36:24 +00:00
|
|
|
|
2015-02-12 17:03:09 +00:00
|
|
|
echo '{"interfaces":{}}' > data.json
|
2014-07-17 12:36:24 +00:00
|
|
|
|
2015-02-12 17:03:09 +00:00
|
|
|
function update() {
|
|
|
|
jq "$1" data.json > temp.json || troubleshoot
|
|
|
|
mv temp.json data.json
|
2014-07-17 12:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2015-02-12 17:03:09 +00:00
|
|
|
update ".interfaces[\"$iface\"] = {mac: \"$MAC\", ip: \"$IP\"}"
|
2014-07-17 12:36:24 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# NOTE(dtantsur): workaround for IPMI device not present on some systems
|
2015-02-12 17:03:09 +00:00
|
|
|
function modprobe_ipmi() {
|
|
|
|
modprobe ipmi_$1 || echo "WARNING: modprobe ipmi_$1 failed, ipmitool call may fail later"
|
|
|
|
}
|
|
|
|
|
|
|
|
modprobe_ipmi msghandler
|
|
|
|
modprobe_ipmi devintf
|
|
|
|
modprobe_ipmi si
|
2014-07-17 12:36:24 +00:00
|
|
|
|
|
|
|
BMC_ADDRESS=$(ipmitool lan print | grep -e "IP Address [^S]" | awk '{ print $4 }')
|
2015-02-12 17:03:09 +00:00
|
|
|
update ".ipmi_address = \"$BMC_ADDRESS\""
|
2014-07-17 12:36:24 +00:00
|
|
|
|
|
|
|
CPU_ARCH=$(lscpu | grep Architecture | awk '{ print $2 }')
|
2015-02-12 17:03:09 +00:00
|
|
|
update ".cpu_arch = \"$CPU_ARCH\""
|
|
|
|
|
2015-02-16 10:41:30 +00:00
|
|
|
RAM=0
|
|
|
|
for i in $(dmidecode --type memory | grep Size | awk '{ print $2; }' | grep -E '[0-9]+');
|
|
|
|
do
|
|
|
|
RAM=$(( RAM + $i ));
|
|
|
|
done
|
2015-02-12 17:03:09 +00:00
|
|
|
update ".memory_mb = $RAM"
|
|
|
|
|
2014-07-17 12:36:24 +00:00
|
|
|
CPUS=$(cat /proc/cpuinfo | grep processor | wc -l)
|
2015-02-12 17:03:09 +00:00
|
|
|
update ".cpus = $CPUS"
|
|
|
|
|
|
|
|
DISK_BYTES=$(fdisk -l | grep Disk | awk '{print $5}' | head -n 1)
|
2014-07-17 12:36:24 +00:00
|
|
|
# NOTE(dtantsur): -1 is required to give Ironic some spacing for partitioning and may be removed later
|
2015-02-12 17:03:09 +00:00
|
|
|
DISK_SIZE=$(($DISK_BYTES/1024/1024/1024 - 1))
|
|
|
|
update ".local_gb = $DISK_SIZE"
|
|
|
|
|
|
|
|
BOOTIF=$(get_kernel_parameter BOOTIF)
|
|
|
|
update ".boot_interface = \"$BOOTIF\""
|
|
|
|
|
|
|
|
echo Collected:
|
|
|
|
cat data.json
|
|
|
|
|
|
|
|
RESULT=$(eval curl -i -X POST \
|
|
|
|
"-H 'Accept: application/json'" \
|
|
|
|
"-H 'Content-Type: application/json'" \
|
|
|
|
"-d @data.json" \
|
|
|
|
"$DISCOVERD_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
|
2014-07-17 12:36:24 +00:00
|
|
|
|
2015-02-12 17:03:09 +00:00
|
|
|
JSON_RESP=$(echo $RESULT | tr '\r' '\n' | tail -n1) # drop HTTP headers
|
2015-02-12 13:20:56 +00:00
|
|
|
|
|
|
|
if echo "$JSON_RESP" | jq '.ipmi_setup_credentials' | grep -q true; then
|
|
|
|
USERNAME=$(echo "$JSON_RESP" | jq -r '.ipmi_username')
|
|
|
|
if [ -z "$USERNAME" ]; then
|
|
|
|
echo "Empty IPMI user name"
|
|
|
|
troubleshoot
|
|
|
|
fi
|
|
|
|
PASSWORD=$(echo "$JSON_RESP" | jq -r '.ipmi_password')
|
|
|
|
if [ -z "$PASSWORD" ]; then
|
|
|
|
echo "Empty IPMI password"
|
|
|
|
troubleshoot
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Assigning IPMI credentials: user $USERNAME"
|
|
|
|
ipmitool user set name 2 $USERNAME
|
|
|
|
ipmitool user set password 2 $PASSWORD
|
|
|
|
# Assign priviledges just in case
|
|
|
|
ipmitool channel setaccess 1 2 link=on ipmi=on callin=on privilege=4
|
|
|
|
ipmitool user enable 2
|
|
|
|
fi
|
2014-07-17 12:36:24 +00:00
|
|
|
|
|
|
|
echo "Node is now discovered! Halting..."
|
|
|
|
# Give user a chance of seeing the output
|
|
|
|
sleep 5
|
|
|
|
poweroff -f
|