xcat-core/xCAT-nbroot2/dodiscovery
jbjohnso 777176fea6 Switch nbroot2 to bash (at size cost, but so many scripts fail in dash)
Implement DHCP driven TZ database (with TZ space reclaimed after assignment)
Fix DHCP on multpile nics (dhclient must have per-interface pid files, sharing a leases is ok though)


git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@10120 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
2011-07-19 15:00:21 +00:00

127 lines
4.4 KiB
Bash
Executable File

#!/bin/sh
minixcatd.awk &
echo "Beginning node discovery process"
NICSTOBRINGUP=`ip link|grep mtu|grep -v LOOPBACK|grep -v usb|grep -v ,UP|awk -F: '{print $2}'`
for nic in $NICSTOBRINGUP; do
dhclient -pf /var/run/dhclient.$nic.pid $nic &
#no need to go out of our way for superfluous ipv6 nics
done
waitforlink=100
while [ ! -z "$NICSTOBRINGUP" -a $waitforlink -gt 0 ]; do
NICSTOBRINGUP=`ip link|grep mtu|grep -v LOOPBACK|grep -v usb|grep -v ,LOWER_UP|awk -F: '{print $2}'`
waitforlink=$((waitforlink - 1))
sleep 0.1
if [ $waitforlink = 1 ]; then
echo "No link detected on $NICSTOBRINGUP"
fi
done
NICSGETTINGADDR=`ip link|grep mtu|grep -v LOOPBACK|grep -v usb|grep ,LOWER_UP|awk -F: '{print $2}'`
timewaiting=0
echo "Waiting for nics to get addresses"
while [ ! -z "$NICSGETTINGADDR" -a $timewaiting != 700 ]; do
NEWNICSGETTINGADDR=""
for nic in $NICSGETTINGADDR; do
if ! ip addr show dev $nic |grep -v inet6|grep inet >/dev/null; then
NEWNICSGETTINGADDR="$NEWNICSGETTINGADDR $nic"
else
echo -n "$nic|"
ip addr show dev $nic |grep -v inet6|grep inet|sed -e s/\\/.*//|awk '{print $2}'
fi
done
sleep 0.1
timewaiting=$((timewaiting+1))
if [ $timewaiting = 450 ]; then
echo "45 seconds without an address on $nic, is spanning tree set to slow?"
fi
if [ $timewaiting = 699 ]; then
echo "No DHCP answer for $nic, ignoring interface"
fi
NICSGETTINGADDR=$NEWNICSGETTINGADDR
done
echo "Stopped waiting on nics to get addresses"
XCATPORT=3001
export XCATPORT
for parm in `cat /proc/cmdline`; do
key=`echo $parm|awk -F= '{print $1}'`
if [ "$key" = "xcatd" ]; then
XCATMASTER=`echo $parm|awk -F= '{print $2}'|awk -F: '{print $1}'`
XCATPORT=`echo $parm|awk -F= '{print $2}'|awk -F: '{print $2}'`
fi
done
#time to make our packet...
MTM=unknown
SERIAL=unknown
ARCH=unknown
ARCH=`uname -m` #32-bit only is old news
if [ -r /sys/devices/virtual/dmi/id/product_name ]; then #x86
PRODNAME=`cat /sys/devices/virtual/dmi/id/product_name`
IAMAVM=0
if [ "$PRODNAME" = "KVM" ]; then
IAMAVM=1
MTM=KVM
elif [ "$PRODNAME" = "VMware Virtual Platform" ]; then
IAMAVM=1
MTM=VMware
else
MTM=`cat /sys/devices/virtual/dmi/id/product_name|awk -F'[' '{print $2}'|awk -F']' '{print $1}'`
fi
elif [ -r /proc/device-tree/model ]; then #POWER
MTM=`cat /proc/device-tree/model |awk -F, '{print $2}'`
fi
CPUCOUNT=`cat /proc/cpuinfo |grep "model name"|wc -l`
MEMORY=`cat /proc/meminfo |grep MemTotal|awk '{print $2}'`
grep "model name" /proc/cpuinfo | while read line; do #to avoid pulling in tail, we do a goofy thing
echo $line > /tmp/cpumod
done
CPUTYPE=`cat /tmp/cpumod|awk -F':' '{print $2}'|sed -e 's/^ //'`
echo '<xcatrequest>' > /tmp/discopacket
echo "<command>findme</command>" >> /tmp/discopacket
echo "<arch>$ARCH</arch>" >> /tmp/discopacket
if [ ! -z "$IAMAVM" ]; then
echo "<nodetype>virtual</nodetype>" >> /tmp/discopacket
fi
echo "<cpucount>$CPUCOUNT</cpucount>" >> /tmp/discopacket
echo "<cputype>$CPUTYPE</cputype>" >> /tmp/discopacket
echo "<memory>$MEMORY</memory>" >> /tmp/discopacket
if [ "$MTM" != "unknown" ]; then
echo "<mtm>$MTM</mtm>" >> /tmp/discopacket
fi
if [ "$SERIAL" != "unknown" ]; then
echo "<serial>$SERIAL</serial>"
fi
for dev in `ip link|grep -B1 ether|grep UP|awk '{print $2}'|sed -e s/://`; do
DRIVER=`grep DRIVER /sys/class/net/$dev/device/uevent|awk -F= '{print $2}'`
ADDRESS=`ip address show dev $dev|grep "inet "|grep global|awk '{print $2}'`
MAC=`ip link show dev $dev|grep ether|awk '{print $2}'`
echo "<mac>$DRIVER|$MAC|$ADDRESS</mac>" >> /tmp/discopacket
done
echo "<xcatpubkey>$PUBKEY</xcatpubkey>" >> /tmp/discopacket #this is not secure to use by itself, switch sourced pubkey for security
echo "<sha512sig>" >> /tmp/discopacket
echo "</sha512sig>" >> /tmp/discopacket
echo "</xcatrequest>" >> /tmp/discopacket
openssl dgst -sha512 -out /tmp/discopacket.sha512 -sign /etc/xcat/privkey.pem /tmp/discopacket
openssl enc -e -a -in /tmp/discopacket.sha512 > /tmp/discopacket.b64sig
cat /tmp/discopacket |while read line; do
if [ "$line" = "</sha512sig>" ]; then
cat /tmp/discopacket.b64sig >> /tmp/discopacket.new
fi
echo $line >> /tmp/discopacket.new
done
mv /tmp/discopacket.new /tmp/discopacket
while [ ! -r /restart ]; do
if [ ! -z "$XCATMASTER" ]; then
(cat /tmp/discopacket | udpcat.awk $XCATMASTER $XCATPORT ) &
fi
for dhcps in `grep dhcp-server /var/lib/dhclient/dhclient.leases|awk '{print $4}'|sed -s 's/;//'`; do
(cat /tmp/discopacket | udpcat.awk $dhcps $XCATPORT ) &
done
cat /tmp/discopacket
sleep 5
done